libzypp
17.25.8
|
Execute a program and give access to its io An object of this class encapsulates the execution of an external program. More...
#include <ExternalProgram.h>
Public Types | |
enum | Stderr_Disposition { Normal_Stderr, Discard_Stderr, Stderr_To_Stdout, Stderr_To_FileDesc } |
Define symbols for different policies on the handling of stderr. More... | |
typedef std::vector< std::string > | Arguments |
typedef std::map< std::string, std::string > | Environment |
For passing additional environment variables to set. More... | |
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 Pathname &root="") | |
Start the external program by using the shell /bin/sh More... | |
ExternalProgram () | |
Start an external program by giving the arguments as an arry of char *pointers. More... | |
ExternalProgram (const Arguments &argv, Stderr_Disposition stderr_disp=Normal_Stderr, bool use_pty=false, int stderr_fd=-1, bool default_locale=false, const 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 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 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 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 () |
Wait for the progamm to complete. More... | |
bool | kill () |
Kill the program. More... | |
bool | kill (int sig) |
Send a signal to the program. More... | |
bool | running () |
Return whether program is running. More... | |
pid_t | getpid () |
return pid More... | |
const std::string & | command () const |
The command we're executing. More... | |
const std::string & | execError () const |
Some detail telling why the execution failed, if it failed. More... | |
std::ostream & | operator>> (std::ostream &out_r) |
Redirect all command output to an ostream . More... | |
![]() | |
ExternalDataSource (FILE *inputfile=0, FILE *outputfile=0) | |
Create a new instance. More... | |
virtual | ~ExternalDataSource () |
Implicitly close the connection. More... | |
bool | send (const char *buffer, size_t length) |
Send some data to the output stream. More... | |
bool | send (std::string s) |
Send some data down the stream. More... | |
size_t | receive (char *buffer, size_t length) |
Read some data from the input stream. More... | |
std::string | receiveLine () |
Read one line from the input stream. More... | |
std::string | receiveLine (io::timeout_type timeout) |
Read one line from the input stream. More... | |
std::string | receiveUpto (char c) |
Read characters into a string until delimiter c or EOF is read. More... | |
std::string | receiveUpto (char c, io::timeout_type timeout) |
Read characters into a string until delimiter c or EOF is read or the timeout is reached. More... | |
void | setBlocking (bool mode) |
Set the blocking mode of the input stream. More... | |
FILE * | inputFile () const |
Return the input stream. More... | |
FILE * | outputFile () const |
Return the output stream. More... | |
Static Public Member Functions | |
static void | renumber_fd (int origfd, int newfd) |
origfd will be accessible as newfd and closed (unless they were equal) More... | |
Protected Member Functions | |
int | checkStatus (int) |
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, bool switch_pgid=false, bool die_with_parent=false) |
Private Attributes | |
bool | use_pty |
Set to true, if a pair of ttys is used for communication instead of a pair of pipes. More... | |
pid_t | pid |
int | _exitStatus |
std::string | _command |
Store the command we're executing. More... | |
std::string | _execError |
Remember execution errors like failed fork/exec. More... | |
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.
Definition at line 59 of file ExternalProgram.h.
typedef std::vector<std::string> zypp::ExternalProgram::Arguments |
Definition at line 64 of file ExternalProgram.h.
typedef std::map<std::string,std::string> zypp::ExternalProgram::Environment |
For passing additional environment variables to set.
Definition at line 81 of file ExternalProgram.h.
Define symbols for different policies on the handling of stderr.
Enumerator | |
---|---|
Normal_Stderr | |
Discard_Stderr | |
Stderr_To_Stdout | |
Stderr_To_FileDesc |
Definition at line 70 of file ExternalProgram.h.
zypp::ExternalProgram::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 = "" |
||
) |
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 just 'cd' if '/'l; nothing if empty |
Definition at line 46 of file ExternalProgram.cc.
zypp::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.
Initial args starting with #
are discarded but some are treated specially: #/[path] - chdir to /[path] before executing
Stdin redirection: If the 1st argument starts with a '<', the remaining part is treated as file opened for reading on standard input (or /dev/null
if empty).
Stdout redirection: If the 1st argument starts with a '>', the remaining part is treated as file opened for writing on standard output (or /dev/null
if empty).
Definition at line 40 of file ExternalProgram.cc.
zypp::ExternalProgram::ExternalProgram | ( | const Arguments & | argv, |
Stderr_Disposition | stderr_disp = Normal_Stderr , |
||
bool | use_pty = false , |
||
int | stderr_fd = -1 , |
||
bool | default_locale = false , |
||
const Pathname & | root = "" |
||
) |
Definition at line 65 of file ExternalProgram.cc.
zypp::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 Pathname & | root = "" |
||
) |
Definition at line 87 of file ExternalProgram.cc.
zypp::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 Pathname & | root = "" |
||
) |
Definition at line 111 of file ExternalProgram.cc.
zypp::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 Pathname & | root = "" |
||
) |
Definition at line 124 of file ExternalProgram.cc.
zypp::ExternalProgram::ExternalProgram | ( | const char * | binpath, |
const char *const * | argv_1, | ||
bool | use_pty = false |
||
) |
Definition at line 138 of file ExternalProgram.cc.
zypp::ExternalProgram::ExternalProgram | ( | const char * | binpath, |
const char *const * | argv_1, | ||
const Environment & | environment, | ||
bool | use_pty = false |
||
) |
Definition at line 154 of file ExternalProgram.cc.
zypp::ExternalProgram::~ExternalProgram | ( | ) |
Definition at line 171 of file ExternalProgram.cc.
|
virtual |
Wait for the progamm to complete.
Reimplemented from zypp::externalprogram::ExternalDataSource.
Definition at line 456 of file ExternalProgram.cc.
bool zypp::ExternalProgram::kill | ( | ) |
Kill the program.
Definition at line 575 of file ExternalProgram.cc.
bool zypp::ExternalProgram::kill | ( | int | sig | ) |
Send a signal to the program.
Definition at line 585 of file ExternalProgram.cc.
bool zypp::ExternalProgram::running | ( | ) |
Return whether program is running.
Definition at line 595 of file ExternalProgram.cc.
|
inline |
return pid
Definition at line 171 of file ExternalProgram.h.
|
inline |
The command we're executing.
Definition at line 174 of file ExternalProgram.h.
|
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).
Definition at line 186 of file ExternalProgram.h.
|
static |
origfd will be accessible as newfd and closed (unless they were equal)
Definition at line 619 of file ExternalProgram.cc.
std::ostream & zypp::ExternalProgram::operator>> | ( | std::ostream & | out_r | ) |
Redirect all command output to an ostream
.
Returns when the command has completed.
Definition at line 631 of file ExternalProgram.cc.
|
protected |
Definition at line 535 of file ExternalProgram.cc.
|
protected |
Definition at line 182 of file ExternalProgram.cc.
|
private |
Set to true, if a pair of ttys is used for communication instead of a pair of pipes.
Definition at line 225 of file ExternalProgram.h.
|
private |
Definition at line 227 of file ExternalProgram.h.
|
private |
Definition at line 228 of file ExternalProgram.h.
|
private |
Store the command we're executing.
Definition at line 230 of file ExternalProgram.h.
|
private |
Remember execution errors like failed fork/exec.
Definition at line 232 of file ExternalProgram.h.