yast2-core
Public Member Functions | Private Member Functions | Private Attributes | List of all members
Process Class Reference

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>

Inheritance diagram for Process:
ExternalProgram ExternalDataSource

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 ()
 
- Public Member Functions inherited from 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="", 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 ()
 
- Public Member Functions inherited from ExternalDataSource
 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 &)
 
Processoperator= (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

- Public Types inherited from ExternalProgram
enum  Stderr_Disposition { Normal_Stderr, Discard_Stderr, Stderr_To_Stdout, Stderr_To_FileDesc }
 
typedef std::map< std::string,
std::string > 
Environment
 
- Static Public Member Functions inherited from ExternalProgram
static void renumber_fd (int origfd, int newfd)
 
- Protected Member Functions inherited from ExternalProgram
int checkStatus (int)
 
- Protected Attributes inherited from ExternalDataSource
FILE * inputfile
 
FILE * outputfile
 

Detailed Description

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.

Constructor & Destructor Documentation

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 >.

Parameters
commandlinea shell commandline that is appended to /bin/sh -c.
default_localewhether to set LC_ALL=C before starting
use_ptystart 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 ( )

Member Function Documentation

bool Process::anyLineInStdout ( )

Read whether there are some buffered lines

References BufferNewStdoutLines(), IsAnyLineInBuffer(), and stdout_buffer.

void Process::BufferNewStdoutLines ( )
private
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 ( )

Return the stderror stream

References stderr_output.

Referenced by main().

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 ( int  sig)

Send a signal

References ExternalProgram::getpid().

bool Process::kill ( )

Send SIGKILL

References ExternalProgram::kill().

Referenced by ~Process().

Process& Process::operator= ( const Process )
private
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().

Member Data Documentation

std::string Process::stderr_buffer
private
FILE* Process::stderr_output
private
std::string Process::stdout_buffer
private

The documentation for this class was generated from the following files:

Generated on a sunny day for yast2-core by doxygen 1.8.8