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

27 {
28 if (gSystem->Exec (cmd.c_str()) != 0)
29 RCU_THROW_MSG ("command failed: " + cmd);
30 }
#define RCU_THROW_MSG(message)
Definition PrintMsg.h:53

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

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

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

46 {
47 std::string result;
48 FILE *pipe = 0;
49 try
50 {
51 std::vector<char> buffer (1024);
52 size_t read;
53
54 pipe = popen (cmd.c_str(), "r");
55 while ((read = fread (&buffer[0], 1, buffer.size(), pipe)) > 0)
56 {
57 result.append (&buffer[0], read);
58 }
59 rc = pclose (pipe);
60 pipe = nullptr;
61 return result;
62 } catch (...)
63 {
64 if (pipe)
65 rc = pclose (pipe);
66 throw;
67 }
68 }
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 72 of file ShellExec.cxx.

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