ATLAS Offline Software
Functions
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 More...
 
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 More...
 
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 More...
 
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 More...
 

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  }

◆ 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  }

◆ 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  }

◆ 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  }
read
IovVectorMap_t read(const Folder &theFolder, const SelectionCriterion &choice, const unsigned int limit=10)
Definition: openCoraCool.cxx:569
get_generator_info.result
result
Definition: get_generator_info.py:21
rerun_display.cmd
string cmd
Definition: rerun_display.py:67
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
createCoolChannelIdFile.buffer
buffer
Definition: createCoolChannelIdFile.py:12
RCU::Shell::exec_read
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...
Definition: ShellExec.cxx:48
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
RCU_THROW_MSG
#define RCU_THROW_MSG(message)
Definition: PrintMsg.h:58
python.trfValidateRootFile.rc
rc
Definition: trfValidateRootFile.py:355