ATLAS Offline Software
Loading...
Searching...
No Matches
RCU::Shell Namespace Reference

Functions

void exec (const std::string &cmd)
 effects: execute the given command guarantee: strong failures: out of memory II failures: system failure failures: command failure
std::string exec_read (const std::string &cmd)
 effects: execute the given command and return the output returns: the output of the command guarantee: strong failures: out of memory III failures: system failure failures: command failure
std::string exec_read (const std::string &cmd, int &rc)
 effects: execute the given command and return the output returns: the output of the command guarantee: strong failures: out of memory III failures: system failure failures: command failure
std::string quote (const std::string &name)
 effects: quote the given name to protect it from the shell returns: the quoted name guarantee: strong failures: out of memory II

Function Documentation

◆ exec()

void RCU::Shell::exec ( const std::string & cmd)

effects: execute the given command guarantee: strong failures: out of memory II failures: system failure failures: command failure

Definition at line 29 of file ShellExec.cxx.

30 {
31 if (gSystem->Exec (cmd.c_str()) != 0)
32 RCU_THROW_MSG ("command failed: " + cmd);
33 }
#define RCU_THROW_MSG(message)
Definition PrintMsg.h:58

◆ exec_read() [1/2]

std::string RCU::Shell::exec_read ( const std::string & cmd)

effects: execute the given command and return the output returns: the output of the command guarantee: strong failures: out of memory III failures: system failure failures: command failure

Definition at line 37 of file ShellExec.cxx.

38 {
39 int rc = 0;
40 std::string result = exec_read (cmd, rc);
41 if (rc != 0)
42 RCU_THROW_MSG ("command failed: " + cmd + "\nwith output:\n" + result);
43 return result;
44 }
static Double_t rc
std::string exec_read(const std::string &cmd)
effects: execute the given command and return the output returns: the output of the command guarantee...
Definition ShellExec.cxx:37

◆ exec_read() [2/2]

std::string RCU::Shell::exec_read ( const std::string & cmd,
int & rc )

effects: execute the given command and return the output returns: the output of the command guarantee: strong failures: out of memory III failures: system failure failures: command failure

Definition at line 48 of file ShellExec.cxx.

49 {
50 std::string result;
51 FILE *pipe = 0;
52 try
53 {
54 std::vector<char> buffer (1024);
55 size_t read;
56
57 pipe = popen (cmd.c_str(), "r");
58 while ((read = fread (&buffer[0], 1, buffer.size(), pipe)) > 0)
59 {
60 result.append (&buffer[0], read);
61 }
62 rc = pclose (pipe);
63 pipe = nullptr;
64 return result;
65 } catch (...)
66 {
67 if (pipe)
68 rc = pclose (pipe);
69 throw;
70 }
71 }
IovVectorMap_t read(const Folder &theFolder, const SelectionCriterion &choice, const unsigned int limit=10)

◆ quote()

std::string RCU::Shell::quote ( const std::string & name)

effects: quote the given name to protect it from the shell returns: the quoted name guarantee: strong failures: out of memory II

Definition at line 75 of file ShellExec.cxx.

76 {
77 std::string result;
78 for (std::string::const_iterator iter = name.begin(),
79 end = name.end(); iter != end; ++ iter)
80 {
81 if (!isalnum (*iter) && *iter != '/' && *iter != '.' &&
82 *iter != '-')
83 result += '\\';
84 result += *iter;
85 };
86 if (result.empty())
87 result = "\"\"";
88 return result;
89 }