#include <utilmm/system/process.hh>
Public Types | |
enum | Stream { Stdout = 1, Stderr = 2 } |
Public Member Functions | |
process () | |
~process () | |
void | set_workdir (boost::filesystem::path const &dir) |
boost::filesystem::path | workdir () const |
std::list< std::string > | cmdline () const |
void | push (const std::string &arg) |
process & | operator<< (std::string const &newarg) |
void | clear () |
void | start () |
void | signal (int signo=SIGINT) |
void | wait () |
void | detach () |
void | erase_redirection (Stream stream) |
void | redirect_to (Stream stream, int handle, bool auto_close=true) |
void | redirect_to (Stream stream, FILE *handle, bool auto_close=true) |
void | redirect_to (Stream stream, boost::filesystem::path const &file) |
void | set_environment (const std::string &key, const std::string &value) |
std::string | environment (const std::string &key) const |
void | clear_environment () |
void | set_pgid (pid_t pid) |
bool | exit_normal () const |
int | exit_status () const |
pid_t | pid () const |
bool | running () |
Static Public Member Functions | |
static void | install_sigint_handler () |
static void | killall () |
Static Public Attributes | |
static const int | InvalidHandle = -1 |
Classes | |
class | already_running |
struct | output_file |
utilmm::process::process | ( | ) |
utilmm::process::~process | ( | ) |
void utilmm::process::set_workdir | ( | boost::filesystem::path const & | dir | ) |
Set the working directory
boost::filesystem::path utilmm::process::workdir | ( | ) | const |
Get the working directory
std::list<std::string> utilmm::process::cmdline | ( | ) | const |
Get the list of elements in the command line. It includes the process name.
void utilmm::process::push | ( | const std::string & | arg | ) |
Add an element on the command line
void utilmm::process::clear | ( | ) |
Clear the command line
void utilmm::process::start | ( | ) |
Start the process
unix_error | an error occured while starting the process | |
already_running | this process object has already started |
void utilmm::process::signal | ( | int | signo = SIGINT |
) |
Send a signal to a running process
unix_error | an error occured |
static void utilmm::process::install_sigint_handler | ( | ) | [static] |
Install a SIGINT handler which calls process::killall
static void utilmm::process::killall | ( | ) | [static] |
Kill all processes managed by a process instance It is safe to call this inside a signal handler
void utilmm::process::wait | ( | ) |
void utilmm::process::detach | ( | ) |
void utilmm::process::erase_redirection | ( | Stream | stream | ) |
Removes any redirection for stream
stream | the output stream to consider |
void utilmm::process::redirect_to | ( | Stream | stream, | |
int | handle, | |||
bool | auto_close = true | |||
) |
Redirects the program output to a file or an already opened file descriptor
process prs; tempfile tmp("basename"); prs.redirect_to(process::Stdout, tmp.fd(), true);
process prs; prs.redirect_to(process::Stdout, "my_output_file");
stream | the output stream, either StdOut or StdErr | |
handle | the file handle to redirect to, or InvalidHandle | |
auto_close | if the file descriptor is owned by this object. If this flag is true, there is no more guarantee as to the status of the file descriptor. It can be closed anytime by the process object |
void utilmm::process::redirect_to | ( | Stream | stream, | |
FILE * | handle, | |||
bool | auto_close = true | |||
) |
void utilmm::process::redirect_to | ( | Stream | stream, | |
boost::filesystem::path const & | file | |||
) |
void utilmm::process::set_environment | ( | const std::string & | key, | |
const std::string & | value | |||
) |
Override an environment variable This function sets or overrides an environment variable for the subprocess.
key | the variable name | |
value | the variable value |
std::string utilmm::process::environment | ( | const std::string & | key | ) | const |
Gets an overriden environment variable
key | the variable name |
key
has previously been overriden by a call to process::set_environment void utilmm::process::clear_environment | ( | ) |
Remove any overriden environment variable
void utilmm::process::set_pgid | ( | pid_t | pid | ) |
Set the process group ID at startup. See setpgid(3)
bool utilmm::process::exit_normal | ( | ) | const |
Check if the last running process exited normally
int utilmm::process::exit_status | ( | ) | const |
Get the exit status of the last running process
pid_t utilmm::process::pid | ( | ) | const |
Get the PID of the last running process
bool utilmm::process::running | ( | ) |
Check if the process is running
const int utilmm::process::InvalidHandle = -1 [static] |