FACT++  1.0
bool ReadlineColor::ExecuteShellCommand ( std::ostream &  out,
const std::string &  cmd 
)

Execute a shell command through a pipe. Write stdout to rl_outstream

Parameters
cmdCommand to be executed
Returns
always true

Definition at line 188 of file ReadlineColor.cc.

References kRed.

Referenced by Process().

189 {
190  FILE *pipe = popen(cmd.c_str(), "r");
191  if (!pipe)
192  {
193  out << kRed << "ERROR - Could not create pipe '" << cmd << "': " << strerror(errno) << " [" << errno << "]" << endl;
194  return true;
195  }
196 
197  while (1)
198  {
199  char buf[1024];
200 
201  const size_t sz = fread(buf, 1, 1024, pipe);
202  out.write(buf, sz);
203 
204  if (feof(pipe) || ferror(pipe))
205  break;
206  }
207 
208  out << endl;
209 
210  if (ferror(pipe))
211  out << kRed << "ERROR - Reading from pipe '" << cmd << "': " << strerror(errno) << " [" << errno << "]" << endl;
212 
213  pclose(pipe);
214 
215  return true;
216 }
Set color Red.
Definition: WindowLog.h:17

+ Here is the caller graph for this function: