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 27 of file ShellExec.cxx.

28 {
29 if (gSystem->Exec (cmd.c_str()) != 0)
30 throw std::runtime_error ("command failed: " + cmd);
31 }

◆ 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 35 of file ShellExec.cxx.

36 {
37 int rc = 0;
38 std::string result = exec_read (cmd, rc);
39 if (rc != 0)
40 throw std::runtime_error ("command failed: " + cmd + "\nwith output:\n" + result);
41 return result;
42 }
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:35

◆ 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 46 of file ShellExec.cxx.

47 {
48 std::unique_ptr<FILE, int (*)(FILE*)> pipe (popen (cmd.c_str(), "r"), pclose);
49 if (pipe == nullptr)
50 throw std::runtime_error ("failed to run command: " + cmd);
51
52 std::string result;
53 std::vector<char> buffer (1024);
54 size_t read;
55 while ((read = fread (&buffer[0], 1, buffer.size(), pipe.get())) > 0)
56 {
57 result.append (&buffer[0], read);
58 }
59 rc = pclose (pipe.release());
60 return result;
61 }
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 65 of file ShellExec.cxx.

66 {
67 // wrap the argument in single quotes, which protects every
68 // character from the shell (including newlines); an embedded
69 // single quote is emitted as the standard '\'' sequence
70 std::string result = "'";
71 for (char c : name)
72 {
73 if (c == '\'')
74 result += "'\\''";
75 else
76 result += c;
77 }
78 result += "'";
79 return result;
80 }