DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dunedaq::oks::CommandOutput Struct Reference

Public Member Functions

 CommandOutput (const char *command_name, const OksKernel *k, std::string &cmd)
 ~CommandOutput ()
const std::string & file_name () const
std::string cat2str () const
std::string last_str () const
void check_command_status (int status)

Public Attributes

std::string p_file_name
std::string & p_command
const char * p_command_name

Detailed Description

Definition at line 4770 of file kernel.cpp.

Constructor & Destructor Documentation

◆ CommandOutput()

dunedaq::oks::CommandOutput::CommandOutput ( const char * command_name,
const OksKernel * k,
std::string & cmd )

Definition at line 4787 of file kernel.cpp.

4787 :
4788p_command(cmd), p_command_name(command_name)
4789{
4790 p_file_name = get_temporary_dir() + '/' + command_name + '.' + std::to_string(getpid()) + ':' + std::to_string(reinterpret_cast<std::uintptr_t>(k)) + ".txt";
4791
4792 p_command.append(" &>");
4793 p_command.append(p_file_name);
4794}

◆ ~CommandOutput()

dunedaq::oks::CommandOutput::~CommandOutput ( )

Definition at line 4796 of file kernel.cpp.

4797{
4798 unlink(p_file_name.c_str());
4799}

Member Function Documentation

◆ cat2str()

std::string dunedaq::oks::CommandOutput::cat2str ( ) const

Definition at line 4802 of file kernel.cpp.

4803{
4804 std::ifstream f(p_file_name.c_str());
4805 std::string out;
4806
4807 if(f) {
4808 std::filebuf * buf = f.rdbuf();
4809 while(true) {
4810 char c = buf->sbumpc();
4811 if(c == EOF) break;
4812 else out += c;
4813 }
4814 }
4815
4816 return out;
4817}
FELIX Initialization std::string initerror FELIX queue timed out

◆ check_command_status()

void dunedaq::oks::CommandOutput::check_command_status ( int status)

Definition at line 4849 of file kernel.cpp.

4850{
4851 if (status == -1)
4852 {
4853 std::ostringstream text;
4854 text << "cannot execute command \'" << p_command << "\': " << strerror(errno);
4855 throw RepositoryOperationFailed(p_command_name, text.str());
4856 }
4857 else if (int error_code = WEXITSTATUS(status))
4858 {
4859 std::ostringstream text;
4860 text << p_command.substr(0, p_command.find_first_of(' ')) << " exit with error code " << error_code << ", output:\n" << cat2str();
4861 throw RepositoryOperationFailed(p_command_name, text.str());
4862 }
4863}
const std::string strerror(int error)
Convert C error number to string.
Definition kernel.cpp:119
std::string cat2str() const
Definition kernel.cpp:4802

◆ file_name()

const std::string & dunedaq::oks::CommandOutput::file_name ( ) const
inline

Definition at line 4775 of file kernel.cpp.

4775{return p_file_name;}

◆ last_str()

std::string dunedaq::oks::CommandOutput::last_str ( ) const

Definition at line 4820 of file kernel.cpp.

4821{
4822 std::ifstream f(p_file_name.c_str());
4823 std::string lastline;
4824
4825 if (f.is_open())
4826 {
4827 f.seekg(-1, std::ios_base::end);
4828 if (f.peek() == '\n')
4829 {
4830 f.seekg(-1, std::ios_base::cur);
4831 for (int i = f.tellg(); i >= 0; i--)
4832 {
4833 if (f.peek() == '\n')
4834 {
4835 f.get();
4836 break;
4837 }
4838 f.seekg(i, std::ios_base::beg);
4839 }
4840 }
4841
4842 getline(f, lastline);
4843 }
4844 return lastline;
4845}

Member Data Documentation

◆ p_command

std::string& dunedaq::oks::CommandOutput::p_command

Definition at line 4782 of file kernel.cpp.

◆ p_command_name

const char* dunedaq::oks::CommandOutput::p_command_name

Definition at line 4783 of file kernel.cpp.

◆ p_file_name

std::string dunedaq::oks::CommandOutput::p_file_name

Definition at line 4781 of file kernel.cpp.


The documentation for this struct was generated from the following file: