#include <process.hpp>
|
static void | generic_writer (Process &proc, std::istream &input) |
|
static void | generic_pipe (std::istream &input, std::ostream &output) |
|
static void | fd_input_pipe (int fd, std::ostream &output, const std::atomic< bool > &done) |
|
static int | exec (const std::string &cmd, const std::vector< std::string > &args, std::ostream &cout, std::ostream &cerr, const std::string &input=std::string()) |
|
static int | exec (const std::string &cmd, const std::vector< std::string > &args, std::istream &cin, std::ostream &cout, std::ostream &cerr) |
|
static int | exec_no_redirect (const std::string &cmd, const std::vector< std::string > &args) |
|
static std::tuple< int, std::string, std::string > | exec (const std::string &cmd, const std::vector< std::string > &args, const std::string &input=std::string()) |
|
The Process class represents a child process and its input/output streams.
cypress::Process::Process |
( |
const std::string & |
cmd, |
|
|
const std::vector< std::string > & |
args, |
|
|
bool |
do_redirect = true |
|
) |
| |
Constructor of the process class. Executes the given command with the given arguments.
- Parameters
-
cmd | is the command that should be executed. |
args | is a vector of arguments that should be passed to the command. |
cypress::Process::~Process |
( |
| ) |
|
Destroys the process instance. Waits for the child process to exit.
std::istream& cypress::Process::child_stderr |
( |
| ) |
|
Returns a reference at the child process standard error stream.
- Returns
- a reference at a C++ input stream from which the standard error of the child process can be read.
std::ostream& cypress::Process::child_stdin |
( |
| ) |
|
Returns a reference at the child process standard input stream. Note: use the close_child_stdin() method to close this stream.
- Returns
- a reference at a C++ output stream which can be used to write data to the standard input of the child process.
std::istream& cypress::Process::child_stdout |
( |
| ) |
|
Returns a reference at the child process standard out stream.
- Returns
- a reference at a C++ input stream from which the standard output of the child process can be read.
void cypress::Process::close_child_stdin |
( |
| ) |
|
Closes the childs standard in stream.
static int cypress::Process::exec |
( |
const std::string & |
cmd, |
|
|
const std::vector< std::string > & |
args, |
|
|
std::ostream & |
cout, |
|
|
std::ostream & |
cerr, |
|
|
const std::string & |
input = std::string() |
|
) |
| |
|
static |
Convenience method for executing a child process and sendings its stdout and stderr streams to the given streams.
- Parameters
-
cmd | is the command that should be executed. |
args | is a vector of arguments that should be given to the command. |
cout | is the target stream to which the child process cout should be written. |
cerr | is the target stream to which the child process cerr should be written. |
input | is a string that should be sent to the child process via its stdin. |
- Returns
- the process return code.
static int cypress::Process::exec |
( |
const std::string & |
cmd, |
|
|
const std::vector< std::string > & |
args, |
|
|
std::istream & |
cin, |
|
|
std::ostream & |
cout, |
|
|
std::ostream & |
cerr |
|
) |
| |
|
static |
Convenience method for executing a child process and sendings its stdout and stderr streams to the given streams.
- Parameters
-
cmd | is the command that should be executed. |
args | is a vector of arguments that should be given to the command. |
cin | is a stream which should be sent to the child process. |
cout | is the target stream to which the child process cout should be written. |
cerr | is the target stream to which the child process cerr should be written. |
- Returns
- the process return code.
static std::tuple<int, std::string, std::string> cypress::Process::exec |
( |
const std::string & |
cmd, |
|
|
const std::vector< std::string > & |
args, |
|
|
const std::string & |
input = std::string() |
|
) |
| |
|
static |
Convenience method for executing a child process, sending data via stdin and receiving its output on std::cout and std::cerr.
- Parameters
-
cmd | is the command that should be executed. |
args | is a vector of arguments that should be given to the command. |
input | is a string that should be sent to the child process via its stdin. |
- Returns
- a tuple containing the exit code and the output from stdout and stderr (in this order).
static int cypress::Process::exec_no_redirect |
( |
const std::string & |
cmd, |
|
|
const std::vector< std::string > & |
args |
|
) |
| |
|
static |
Convenience method for executing a child process without redirecting stdin/stdout/stderr.
- Parameters
-
cmd | is the command that should be executed. |
args | is a vector of arguments that should be given to the command. |
- Returns
- the process return code.
int cypress::Process::exitcode |
( |
| ) |
|
Returns the exitcode of the process, as a value between 0 and 255. If the child process was killed by a signal, returns the signal number which killed the process as a negative number. The result is only valid if the child process is no longer running (running() return false, or wait() returned).
- Returns
- the exit code (positive number) or the signal number which killed the child process (negative number).
static void cypress::Process::fd_input_pipe |
( |
int |
fd, |
|
|
std::ostream & |
output, |
|
|
const std::atomic< bool > & |
done |
|
) |
| |
|
static |
Thread proc used to asynchronously pipe data from a source filedescriptor to the target stream.
- Parameters
-
fd | is the input file descriptor. |
output | is the target stream. |
done | should be set to true when the thread should no longer listen on the fd. |
static void cypress::Process::generic_pipe |
( |
std::istream & |
input, |
|
|
std::ostream & |
output |
|
) |
| |
|
static |
Thread proc used to asynchronously pipe data from a source input stream to a target stream. Used to read data from a process.
- Parameters
-
input | is the input stream. |
output | is the target stream. |
static void cypress::Process::generic_writer |
( |
Process & |
proc, |
|
|
std::istream & |
input |
|
) |
| |
|
static |
Thread proc used to asynchronously stream an input stream to a process.
- Parameters
-
proc | is the process to which should be written. |
input | is the stream that should be written to the stdin of the process. |
bool cypress::Process::running |
( |
| ) |
|
Returns true if the child process is still running, false otherwise.
bool cypress::Process::signal |
( |
int |
signal | ) |
|
Sends a UNIX signal to the child process, corresponding to the kill system call.
- Parameters
-
signal | is the UNIX signal that should be sent to the child process. |
- Returns
- true if the operation was successful, false if not, e.g. because the child no longer exists.
int cypress::Process::wait |
( |
| ) |
|
Waits for the child process to exit. Returns the exitcode. See exitcode() for the exact semantics.
The documentation for this class was generated from the following file: