Execute a program and give access to its io An object of this class encapsulates the execution of an external program. It starts the program using fork and some exec.. call, gives you access to the program's stdio/stderr and closes the program after use. More...
#include <Process.h>
Public Member Functions | |
Process (const std::string &commandline, bool use_pty=false, bool default_locale=false, bool pty_trans=true) | |
Process (const char *const *argv, const Environment &environment, bool use_pty=false, bool default_locale=false, bool pty_trans=true) | |
~Process () | |
bool | kill (int sig) |
bool | kill () |
std::string | readLine () |
std::string | read () |
std::string | readErrLine () |
std::string | readErr () |
int | closeAll () |
void | readStdoutToBuffer () |
void | readStderrToBuffer () |
bool | anyLineInStdout () |
FILE * | errorFile () |
Private Member Functions | |
Process (const Process &) | |
Process & | operator= (const Process &) |
int | create_stderr_pipes () |
std::string | GetLineFromBuffer (std::string &buffer) |
void | BufferNewStdoutLines () |
bool | IsAnyLineInBuffer (const std::string &buffer) |
Private Attributes | |
std::string | stdout_buffer |
std::string | stderr_buffer |
FILE * | stderr_output |
Execute a program and give access to its io An object of this class encapsulates the execution of an external program. It starts the program using fork and some exec.. call, gives you access to the program's stdio/stderr and closes the program after use.
Process::Process | ( | const Process & | ) | [private] |
Process::Process | ( | const std::string & | commandline, | |
bool | use_pty = false , |
|||
bool | default_locale = false , |
|||
bool | pty_trans = true | |||
) | [inline] |
Start the external program by using the shell /bin/sh
with the option
-c
. You can use io direction symbols < and >.
commandline | a shell commandline that is appended to /bin/sh -c . | |
default_locale | whether to set LC_ALL=C before starting | |
use_pty | start the process in a terminal |
Process::Process | ( | const char *const * | argv, | |
const Environment & | environment, | |||
bool | use_pty = false , |
|||
bool | default_locale = false , |
|||
bool | pty_trans = true | |||
) | [inline] |
Start an external program by giving the arguments as an arry of char *pointers. If environment is provided, variables will be added to the childs environment, overwriting existing ones.
Process::~Process | ( | ) |
Destructor
References ExternalProgram::getpid(), kill(), MIL, and ExternalProgram::running().
bool Process::anyLineInStdout | ( | ) |
Read whether there are some buffered lines
References BufferNewStdoutLines(), IsAnyLineInBuffer(), and stdout_buffer.
void Process::BufferNewStdoutLines | ( | ) | [private] |
References ExternalDataSource::receiveUpto(), and stdout_buffer.
Referenced by anyLineInStdout(), and readLine().
int Process::closeAll | ( | ) |
Close all input/output filedescriptors
References ExternalProgram::close(), and stderr_output.
int Process::create_stderr_pipes | ( | ) | [private] |
References stderr_output, and UnblockFD().
FILE * Process::errorFile | ( | ) |
std::string Process::GetLineFromBuffer | ( | std::string & | buffer | ) | [private] |
Referenced by readErrLine(), and readLine().
bool Process::IsAnyLineInBuffer | ( | const std::string & | buffer | ) | [private] |
Referenced by anyLineInStdout().
bool Process::kill | ( | ) |
bool Process::kill | ( | int | sig | ) |
Send a signal
References ExternalProgram::getpid(), and kill().
std::string Process::read | ( | ) |
Read characters from stdout (not line oriented)
References readStdoutToBuffer(), and stdout_buffer.
Referenced by main(), and readStdoutToBuffer().
std::string Process::readErr | ( | ) |
Read characters from stderr (not line oriented)
References readStderrToBuffer(), and stderr_buffer.
Referenced by main().
std::string Process::readErrLine | ( | ) |
Read a line from stderr
References GetLineFromBuffer(), readStderrToBuffer(), and stderr_buffer.
std::string Process::readLine | ( | ) |
Read a line from stdout
References BufferNewStdoutLines(), GetLineFromBuffer(), and stdout_buffer.
void Process::readStderrToBuffer | ( | ) |
Read stderr to the internal buffer (can unblock the process)
References b_size(), ERR, stderr_buffer, and stderr_output.
Referenced by readErr(), and readErrLine().
void Process::readStdoutToBuffer | ( | ) |
Read stdout to the internal buffer (can unblock the process)
References b_size(), read(), ExternalDataSource::receive(), and stdout_buffer.
Referenced by read().
std::string Process::stderr_buffer [private] |
Referenced by readErr(), readErrLine(), and readStderrToBuffer().
FILE* Process::stderr_output [private] |
Referenced by closeAll(), create_stderr_pipes(), errorFile(), and readStderrToBuffer().
std::string Process::stdout_buffer [private] |
Referenced by anyLineInStdout(), BufferNewStdoutLines(), read(), readLine(), and readStdoutToBuffer().