BoosterSeat
0.1
A C++ library that includes common utilities that are used in other projects.
|
A class to handle linux process calls. More...
#include <process.hpp>
Public Member Functions | |
Process (const std::string &cmd, std::vector< std::string > argv) | |
~Process () | |
void | closeInStream () |
int | getExitCode () |
const std::string & | getStderr () |
const std::string & | getStdout () |
void | waitToComplete (unsigned int timeout=1000) |
Waits for the process to complete. If the process does not complete within the timeout, a std::system_error is thrown. More... | |
void | writeToInStream (const std::string &s) |
Private Member Functions | |
void | assertComplete () |
void | child (const std::vector< std::string > &argv) |
void | run (const std::string &cmd, std::vector< std::string > argv) |
Private Attributes | |
int | err_pipe_ [2] |
The file descriptors for error pipe. More... | |
std::istream * | err_stream_ |
The error stream for the child process. More... | |
int | exit_code_ = 0 |
The exit code of the process. More... | |
bool | have_exit_code_ = false |
Set to true when the process has completed and an exit code has been retrieved. This is used internally to check if the process has completed. More... | |
int | in_pipe_ [2] |
The file descriptors for input pipe. More... | |
std::ostream * | in_stream_ |
The input stream for the child process. More... | |
int | out_pipe_ [2] |
The file descriptors for output pipe. More... | |
std::istream * | out_stream_ |
The output stream for the child process. More... | |
__gnu_cxx::stdio_filebuf< char > * | p_err_filebuf_ |
The filebuf for error pipe. More... | |
__gnu_cxx::stdio_filebuf< char > * | p_in_filebuf_ |
The filebuf for input pipe. More... | |
__gnu_cxx::stdio_filebuf< char > * | p_out_filebuf_ |
The filebuf for output pipe. More... | |
pid_t | pid_ |
The process id of the child process. More... | |
std::string | stderr_string_ |
The stderr of the process. More... | |
std::string | stdout_string_ |
The stdout of the process. More... | |
A class to handle linux process calls.
This is a rework of the project cpp-subprocess
bst::Process::Process | ( | const std::string & | cmd, |
std::vector< std::string > | argv | ||
) |
bst::Process::~Process | ( | ) |
References err_stream_, in_stream_, out_stream_, p_err_filebuf_, p_in_filebuf_, and p_out_filebuf_.
void bst::Process::writeToInStream | ( | const std::string & | s | ) |
void bst::Process::closeInStream | ( | ) |
References p_in_filebuf_.
const std::string & bst::Process::getStdout | ( | ) |
References assertComplete(), and stdout_string_.
Referenced by getOutput().
const std::string & bst::Process::getStderr | ( | ) |
References assertComplete(), and stderr_string_.
Referenced by getOutput().
int bst::Process::getExitCode | ( | ) |
References assertComplete(), and exit_code_.
Referenced by getOutput().
void bst::Process::waitToComplete | ( | unsigned int | timeout = 1000 | ) |
Waits for the process to complete. If the process does not complete within the timeout, a std::system_error is thrown.
timeout | The number of milliseconds to wait for the process to exit. Default is 1000ms. |
References err_stream_, exit_code_, have_exit_code_, out_stream_, pid_, bst::PROCESS_TIMEOUT, bst::sleep(), stderr_string_, and stdout_string_.
Referenced by TEST().
|
private |
References have_exit_code_, and bst::PROCESS_NOT_COMPLETE.
Referenced by getExitCode(), getStderr(), and getStdout().
|
private |
References child(), err_pipe_, err_stream_, in_pipe_, in_stream_, bst::K_PIPE_READ, bst::K_PIPE_WRITE, out_pipe_, out_stream_, p_err_filebuf_, p_in_filebuf_, p_out_filebuf_, and pid_.
Referenced by Process().
|
private |
References err_pipe_, in_pipe_, bst::K_PIPE_READ, bst::K_PIPE_WRITE, and out_pipe_.
Referenced by run().
|
private |
The process id of the child process.
Referenced by run(), and waitToComplete().
|
private |
|
private |
|
private |
|
private |
The filebuf for input pipe.
Referenced by ~Process(), closeInStream(), and run().
|
private |
The filebuf for output pipe.
Referenced by ~Process(), and run().
|
private |
The filebuf for error pipe.
Referenced by ~Process(), and run().
|
private |
The input stream for the child process.
Referenced by ~Process(), run(), and writeToInStream().
|
private |
The output stream for the child process.
Referenced by ~Process(), run(), and waitToComplete().
|
private |
The error stream for the child process.
Referenced by ~Process(), run(), and waitToComplete().
|
private |
Set to true when the process has completed and an exit code has been retrieved. This is used internally to check if the process has completed.
Referenced by assertComplete(), and waitToComplete().
|
private |
The exit code of the process.
Referenced by getExitCode(), and waitToComplete().
|
private |
The stdout of the process.
Referenced by getStdout(), and waitToComplete().
|
private |
The stderr of the process.
Referenced by getStderr(), and waitToComplete().