libcamgm
|
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 and closes the program after use. More...
#include <ExternalProgram.hpp>
Public Types | |
enum | Stderr_Disposition { Normal_Stderr, Discard_Stderr, Stderr_To_Stdout, Stderr_To_FileDesc } |
typedef std::vector< std::string > | Arguments |
typedef std::map< std::string, std::string > | Environment |
Public Member Functions | |
ExternalProgram (std::string commandline, Stderr_Disposition stderr_disp=Normal_Stderr, bool use_pty=false, int stderr_fd=-1, bool default_locale=false, const path::PathName &root="") | |
ExternalProgram () | |
ExternalProgram (const Arguments &argv, Stderr_Disposition stderr_disp=Normal_Stderr, bool use_pty=false, int stderr_fd=-1, bool default_locale=false, const path::PathName &root="") | |
ExternalProgram (const Arguments &argv, const Environment &environment, Stderr_Disposition stderr_disp=Normal_Stderr, bool use_pty=false, int stderr_fd=-1, bool default_locale=false, const path::PathName &root="") | |
ExternalProgram (const char *const *argv, Stderr_Disposition stderr_disp=Normal_Stderr, bool use_pty=false, int stderr_fd=-1, bool default_locale=false, const path::PathName &root="") | |
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 path::PathName &root="") | |
ExternalProgram (const char *binpath, const char *const *argv_1, bool use_pty=false) | |
ExternalProgram (const char *binpath, const char *const *argv_1, const Environment &environment, bool use_pty=false) | |
~ExternalProgram () | |
int | close () |
bool | kill () |
bool | running () |
pid_t | getpid () |
const std::string & | command () const |
const std::string & | execError () const |
![]() | |
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 |
Static Public Member Functions | |
static void | renumber_fd (int origfd, int newfd) |
Protected Member Functions | |
int | checkStatus (int) |
Private Member Functions | |
void | start_program (const char *const *argv, const Environment &environment, Stderr_Disposition stderr_disp=Normal_Stderr, int stderr_fd=-1, bool default_locale=false, const char *root=NULL) |
Private Attributes | |
bool | use_pty |
pid_t | pid |
int | _exitStatus |
std::string | _command |
std::string | _execError |
Additional Inherited Members | |
![]() | |
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 and closes the program after use.
typedef std::vector<std::string> ca_mgm::ExternalProgram::Arguments |
typedef std::map<std::string,std::string> ca_mgm::ExternalProgram::Environment |
For passing additional environment variables to set
ca_mgm::ExternalProgram::ExternalProgram | ( | std::string | commandline, |
Stderr_Disposition | stderr_disp = Normal_Stderr , |
||
bool | use_pty = false , |
||
int | stderr_fd = -1 , |
||
bool | default_locale = false , |
||
const path::PathName & | root = "" |
||
) |
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 |
root | directory to chroot into, / or empty to not chroot |
ca_mgm::ExternalProgram::ExternalProgram | ( | ) |
Start an external program by giving the arguments as an arry of char *pointers. If environment is provided, varaiables will be added to the childs environment, overwriting existing ones.
ExternalProgramException | if fork fails. |
ca_mgm::ExternalProgram::ExternalProgram | ( | const Arguments & | argv, |
Stderr_Disposition | stderr_disp = Normal_Stderr , |
||
bool | use_pty = false , |
||
int | stderr_fd = -1 , |
||
bool | default_locale = false , |
||
const path::PathName & | root = "" |
||
) |
ca_mgm::ExternalProgram::ExternalProgram | ( | const Arguments & | argv, |
const Environment & | environment, | ||
Stderr_Disposition | stderr_disp = Normal_Stderr , |
||
bool | use_pty = false , |
||
int | stderr_fd = -1 , |
||
bool | default_locale = false , |
||
const path::PathName & | root = "" |
||
) |
ca_mgm::ExternalProgram::ExternalProgram | ( | const char *const * | argv, |
Stderr_Disposition | stderr_disp = Normal_Stderr , |
||
bool | use_pty = false , |
||
int | stderr_fd = -1 , |
||
bool | default_locale = false , |
||
const path::PathName & | root = "" |
||
) |
ca_mgm::ExternalProgram::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 path::PathName & | root = "" |
||
) |
ca_mgm::ExternalProgram::ExternalProgram | ( | const char * | binpath, |
const char *const * | argv_1, | ||
bool | use_pty = false |
||
) |
ca_mgm::ExternalProgram::ExternalProgram | ( | const char * | binpath, |
const char *const * | argv_1, | ||
const Environment & | environment, | ||
bool | use_pty = false |
||
) |
ca_mgm::ExternalProgram::~ExternalProgram | ( | ) |
|
protected |
Referenced by execError().
|
virtual |
Close the input and output streams.
Reimplemented from ca_mgm::ExternalDataSource.
|
inline |
The command we're executing.
References _command.
|
inline |
Some detail telling why the execution failed, if it failed. Empty if the command is still running or successfully completed.
Can't open pty (s).
Can't open pipe (s).
Can't fork (s).
Command exited with status d.
Command was killed by signal d (s).
References _execError, checkStatus(), and renumber_fd().
|
inline |
return pid
References pid.
bool ca_mgm::ExternalProgram::kill | ( | ) |
Kill the program
|
static |
origfd will be accessible as newfd and closed (unless they were equal)
Referenced by execError().
bool ca_mgm::ExternalProgram::running | ( | ) |
Return whether program is running
|
private |
|
private |
Store the command we're executing.
Referenced by command().
|
private |
Remember execution errors like failed fork/exec.
Referenced by execError().
|
private |
|
private |
Referenced by getpid().
|
private |
Set to true, if a pair of ttys is used for communication instead of a pair of pipes.