Run an external command, with stdin/stdout/stderr as strings or as streams - like perl backticks. More...
#include <ProcessRunner.h>
Classes | |
| class | BackgroundProcess |
| class | Exception |
| struct | ProcessResultType |
| struct | StringOptions |
| Run () options for mapping Strings - what code page converters to use. More... | |
Public Member Functions | |
| ProcessRunner ()=delete | |
| Construct ProcessRunner with a CommandLine to run (doesn't actually RUN til you call Run or RunInBackground). | |
| nonvirtual void | Run (const Streams::InputStream::Ptr< byte > &in, const Streams::OutputStream::Ptr< byte > &out=nullptr, const Streams::OutputStream::Ptr< byte > &error=nullptr, Time::DurationSeconds timeout=Time::kInfinity) |
| Run the command synchronously, returning its output, and THROW on any failure. | |
| nonvirtual BackgroundProcess | RunInBackground (const Streams::InputStream::Ptr< byte > &in=nullptr, const Streams::OutputStream::Ptr< byte > &out=nullptr, const Streams::OutputStream::Ptr< byte > &error=nullptr) |
| Run the given external command/process (set by constructor) - with the given arguments in the background, and return a handle to the results. | |
| Streams::InputStream::Ptr< byte > | GetStdIn () const |
| Streams::OutputStream::Ptr< byte > | GetStdOut () const |
| Streams::OutputStream::Ptr< byte > | GetStdErr () const |
Run an external command, with stdin/stdout/stderr as strings or as streams - like perl backticks.
There are two ways to run, and the difference is all you really need to know:
o Run () is synchronous. It returns the output, and THROWS on any failure - including the
process merely exiting non-zero. Nothing to check; if it returns, it worked.
o RunInBackground () hands back a BackgroundProcess you wait on and interrogate - exit status,
signal, child pid - so you can treat a failed run as data instead of as an exception.
Run () behaves as if it were RunInBackground (), then waiting, then ProcessResultType::ThrowIfFailed ().
Definition at line 132 of file ProcessRunner.h.
|
delete |
Construct ProcessRunner with a CommandLine to run (doesn't actually RUN til you call Run or RunInBackground).
| nonvirtual void Stroika::Foundation::Execution::ProcessRunner::Run | ( | const Streams::InputStream::Ptr< byte > & | in, |
| const Streams::OutputStream::Ptr< byte > & | out = nullptr, |
||
| const Streams::OutputStream::Ptr< byte > & | error = nullptr, |
||
| Time::DurationSeconds | timeout = Time::kInfinity |
||
| ) |
Run the command synchronously, returning its output, and THROW on any failure.
o STRING overload: pass stdin as a string, get back {stdout, stderr}. Run () with no
argument means Run (""). The simplest form.
o STREAMS overload: pass binary streams instead. Any of the three left nullptr is
redirected to /dev/null.
| nonvirtual BackgroundProcess Stroika::Foundation::Execution::ProcessRunner::RunInBackground | ( | const Streams::InputStream::Ptr< byte > & | in = nullptr, |
| const Streams::OutputStream::Ptr< byte > & | out = nullptr, |
||
| const Streams::OutputStream::Ptr< byte > & | error = nullptr |
||
| ) |
Run the given external command/process (set by constructor) - with the given arguments in the background, and return a handle to the results.
This function is generally quick, and non-blocking - just creates a thread todo the work.
| Streams::InputStream::Ptr< byte > Stroika::Foundation::Execution::ProcessRunner::GetStdIn | ( | ) | const |
If empty, stdin will not be empty (redirected from /dev/null).
Otherwise, the stream will be 'read' by the ProcessRunner and 'fed' downstream to the running subprocess.
Definition at line 100 of file ProcessRunner.inl.
| Streams::OutputStream::Ptr< byte > Stroika::Foundation::Execution::ProcessRunner::GetStdOut | ( | ) | const |
If empty, stdout will not be captured (redirected to /dev/null)
Definition at line 110 of file ProcessRunner.inl.
| Streams::OutputStream::Ptr< byte > Stroika::Foundation::Execution::ProcessRunner::GetStdErr | ( | ) | const |
If empty, stderr will not be captured (redirected to /dev/null)
Definition at line 120 of file ProcessRunner.inl.