wibble::sys::Exec Class Reference

Execute external commands, either forked as a ChildProcess or directly using exec(). More...

`#include <exec.h>`

Inheritance diagram for wibble::sys::Exec:
[legend]
Collaboration diagram for wibble::sys::Exec:
[legend]

## Public Member Functions

virtual | ~Exec ()
| Exec (const std::string &pathname)
| Create a new object that will execute program `program'. More...
void | importEnv ()
| Import the current environment into env. More...
void | exec ()
| exec the program, never returning if all goes well More...
Public Member Functions inherited from wibble::sys::ChildProcess
| ChildProcess ()
virtual | ~ChildProcess ()
void | setExec (std::string command)
| Instead of calling the main() function of this class, execute an external command. More...
pid_t | fork ()
| For a subprocess to run proc. More...
void | setupRedirects (int *stdinfd=0, int *stdoutfd=0, int *stderrfd=0)
pid_t | forkAndRedirect (int *stdinfd=0, int *stdoutfd=0, int *stderrfd=0)
pid_t | pid () const
| Get the pid of the child process or (pid_t)-1 if no child is running. More...
bool | running ()
int | exitStatus ()
void | waitForSuccess ()
int | wait (struct rusage *ru=0)
| Wait for the child to finish, returning its exit status and optionally storing resource usage informations in `ru'. More...
void | kill (int signal)
| Send the given signal to the process. More...

## Public Attributes

std::string | pathname
| Filename or pathname of the program to execute. More...
std::vector< std::string > | args
| Arguments for the process to execute. More...
std::vector< std::string > | env
| Custom environment for the child process, if envFromParent is false. More...
bool | envFromParent
| True if the environment is to be taken from the parent, false if it is explicitly provided in env. More...
bool | searchInPath
| Set to true if the file is to be searched in the current $PATH. More...

## Protected Member Functions

virtual int | main ()
| Used to run the program as a child process, if one of the ChildProcess::fork functions is called. More...
virtual void | spawnChild ()
| On Windows, it's impossible to fork(), but if you were to fork+exec, it's not all lost. More...
Protected Member Functions inherited from wibble::sys::ChildProcess
void | waitError ()
void | setupPipes ()
void | setupPrefork ()
void | setupChild ()
void | setupParent ()

## Additional Inherited Members

Protected Attributes inherited from wibble::sys::ChildProcess
pid_t | _pid
int | pipes [3][2]
int * | _stdin
int * | _stdout
int * | _stderr
int | m_status
bool | m_doExec
std::string | m_command

## Detailed Description

Execute external commands, either forked as a ChildProcess or directly using exec().

## Constructor & Destructor Documentation

## ~Exec()

virtual wibble::sys::Exec::~Exec | ( |  | ) |

inline virtual

## Exec()

wibble::sys::Exec::Exec | ( | const std::string & | pathname | ) |

inline

Create a new object that will execute program `program'.

References exec(), and importEnv().

## Member Function Documentation

## exec()

void wibble::sys::Exec::exec | ( |  | ) |

exec the program, never returning if all goes well

References args, env, envFromParent, environ, pathname, and searchInPath.

Referenced by Exec(), and main().

## importEnv()

void wibble::sys::Exec::importEnv | ( |  | ) |

Import the current environment into env.

References env, and environ.

Referenced by Exec().

## main()

int wibble::sys::Exec::main | ( |  | ) |

protected virtual

Used to run the program as a child process, if one of the ChildProcess::fork functions is called.

Simply calls exec()

Implements wibble::sys::ChildProcess.

References exec().

## spawnChild()

void wibble::sys::Exec::spawnChild | ( |  | ) |

protected virtual

On Windows, it's impossible to fork(), but if you were to fork+exec, it's not all lost.

You can implement spawnChild() instead of main(), which needs to call CreateProcess, spawn or similar. The redirections requested by setupRedirects are respected. Exec and ShellProcess implement spawnChild on Windows.

NB. For wait() to work, the si/pi member variables need to be filled in by the implementation.

Reimplemented from wibble::sys::ChildProcess.

References args, and pathname.

## Member Data Documentation

## args

std::vector<std::string> wibble::sys::Exec::args

Arguments for the process to execute.

args[0] will be passed as the name of the child process

Referenced by exec(), TestChildprocess::redirect(), wibble::sys::ShellCommand::ShellCommand(), and spawnChild().

## env

std::vector<std::string> wibble::sys::Exec::env

Custom environment for the child process, if envFromParent is false.

Referenced by exec(), and importEnv().

## envFromParent

bool wibble::sys::Exec::envFromParent

True if the environment is to be taken from the parent, false if it is explicitly provided in env.

Referenced by exec(), and wibble::sys::ShellCommand::ShellCommand().

## pathname

std::string wibble::sys::Exec::pathname

Filename or pathname of the program to execute.

If searchInPath is true, this just needs to be the file name. Otherwise, it needs to be the absolute path of the file to execute.

Referenced by exec(), and spawnChild().

## searchInPath

bool wibble::sys::Exec::searchInPath

Set to true if the file is to be searched in the current $PATH.

If this is set to true, the environment will always be taken from the parent regardless of the values of envFromParent and env.

Referenced by exec(), TestChildprocess::inout(), TestChildprocess::redirect(), and wibble::sys::ShellCommand::ShellCommand().

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

- exec.h
- exec.cpp