yast2-core
|
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 () |
![]() | |
ExternalProgram (std::string commandline, Stderr_Disposition stderr_disp=Normal_Stderr, bool use_pty=false, int stderr_fd=-1, bool default_locale=false, const Pathname &root="", bool pty_trans=true) | |
ExternalProgram (const char *const *argv, Stderr_Disposition stderr_disp=Normal_Stderr, bool use_pty=false, int stderr_fd=-1, bool default_locale=false, const Pathname &root="", bool pty_trans=true) | |
ExternalProgram (const char *const *argv, const Environment &environment, Stderr_Disposition stderr_disp=Normal_Stderr, bool use_pty=false, int stderr_fd=-1, bool default_locale=false, const Pathname &root="", bool pty_trans=true) | |
ExternalProgram (const char *binpath, const char *const *argv_1, bool use_pty=false, bool pty_trans=true) | |
ExternalProgram (const char *binpath, const char *const *argv_1, const Environment &environment, bool use_pty=false, bool pty_trans=true) | |
~ExternalProgram () | |
int | close () |
bool | kill () |
bool | running () |
pid_t | getpid () |
![]() | |
ExternalDataSource (FILE *inputfile=0, FILE *outputfile=0) | |
virtual | ~ExternalDataSource () |
bool | send (const char *buffer, size_t length) |
bool | send (std::string s) |
size_t | receive (char *buffer, size_t length) |
std::string | receiveLine () |
std::string | receiveUpto (char c) |
void | setBlocking (bool mode) |
FILE * | inputFile () const |
FILE * | outputFile () const |
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 |
Additional Inherited Members | |
![]() | |
enum | Stderr_Disposition { Normal_Stderr, Discard_Stderr, Stderr_To_Stdout, Stderr_To_FileDesc } |
typedef std::map< std::string, std::string > | Environment |
![]() | |
static void | renumber_fd (int origfd, int newfd) |
![]() | |
int | checkStatus (int) |
![]() | |
FILE * | inputfile |
FILE * | outputfile |
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.
|
private |
|
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 |
|
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.
References anyLineInStdout(), closeAll(), errorFile(), kill(), read(), readErr(), readErrLine(), readLine(), readStderrToBuffer(), readStdoutToBuffer(), and ~Process().
Process::~Process | ( | ) |
Destructor
References ExternalProgram::getpid(), kill(), MIL, and ExternalProgram::running().
Referenced by Process().
bool Process::anyLineInStdout | ( | ) |
Read whether there are some buffered lines
References BufferNewStdoutLines(), IsAnyLineInBuffer(), and stdout_buffer.
Referenced by Process().
|
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.
Referenced by Process().
|
private |
References stderr_output, and UnblockFD().
FILE * Process::errorFile | ( | ) |
|
private |
Referenced by readErrLine(), and readLine().
|
private |
Referenced by anyLineInStdout().
bool Process::kill | ( | int | sig | ) |
Send a signal
References ExternalProgram::getpid().
bool Process::kill | ( | ) |
std::string Process::read | ( | ) |
Read characters from stdout (not line oriented)
References readStdoutToBuffer(), and stdout_buffer.
Referenced by main(), Process(), and readStdoutToBuffer().
std::string Process::readErr | ( | ) |
Read characters from stderr (not line oriented)
References readStderrToBuffer(), and stderr_buffer.
std::string Process::readErrLine | ( | ) |
Read a line from stderr
References GetLineFromBuffer(), readStderrToBuffer(), and stderr_buffer.
Referenced by Process().
std::string Process::readLine | ( | ) |
Read a line from stdout
References BufferNewStdoutLines(), GetLineFromBuffer(), and stdout_buffer.
Referenced by Process().
void Process::readStderrToBuffer | ( | ) |
Read stderr to the internal buffer (can unblock the process)
References b_size(), ERR, stderr_buffer, and stderr_output.
Referenced by Process(), 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.
|
private |
Referenced by readErr(), readErrLine(), and readStderrToBuffer().
|
private |
Referenced by closeAll(), create_stderr_pipes(), errorFile(), and readStderrToBuffer().
|
private |
Referenced by anyLineInStdout(), BufferNewStdoutLines(), read(), readLine(), and readStdoutToBuffer().