Runs an external program with piped stdin/stdout/stderr. More...
#include <StormByte/system/process.hxx>
Public Types | |
| enum class | Error { Success = 0 , ExecutableNotFound , CreationFailed , Permission , NotRunning , AlreadyExited , TimedOut , BrokenPipe , Canceled } |
| Child-process enumerators. More... | |
| enum class | Status : unsigned short { RUNNING , SUSPENDED , TERMINATED } |
| Process lifecycle. More... | |
Public Member Functions | |
| Process (const std::filesystem::path &prog, const std::vector< StormByte::String::String > &args={}) noexcept | |
| Construct and start. | |
| Process (std::filesystem::path &&prog, std::vector< StormByte::String::String > &&args={}) noexcept | |
| Construct and start (moved). | |
| Process (const Process &proc)=delete | |
| Process (Process &&proc) noexcept | |
| Move constructor (invalidates the source). | |
| Process & | operator= (const Process &proc)=delete |
| Process & | operator= (Process &&proc) noexcept |
| Move assignment (invalidates the source). | |
| virtual | ~Process () noexcept |
| Destructor (waits if still owning a child, then frees pipes). | |
| operator bool () const noexcept | |
| Whether a child is live. | |
| StormByte::Error::Fault | Fault () const noexcept |
| Last Process error. | |
| int | Wait () noexcept |
| Block until the process exits (no timeout). | |
| int | Wait (std::chrono::milliseconds timeout) noexcept |
Wait for the process to exit up to timeout. | |
| pid_t | Pid () noexcept |
| Child PID. | |
| void | Suspend () |
| Suspend the child process. | |
| void | Resume () |
| Resume a suspended child process. | |
| Process & | operator>> (Process &proc) |
Forward this process stdout to proc stdin (background thread). | |
| std::string & | operator>> (std::string &str) const |
| Read remaining stdout into a caller-owned string. | |
| StormByte::String::String & | operator>> (StormByte::String::String &str) const |
| Read remaining stdout into owned text. | |
| std::string & | Stderr (std::string &str) const |
| Read remaining stderr into a caller-owned string. | |
| StormByte::String::String & | Stderr (StormByte::String::String &str) const |
| Read remaining stderr into owned text. | |
| Process & | operator<< (std::string_view str) |
| Write UTF-8 text to process stdin. | |
| Process & | operator<< (const StormByte::String::String &str) |
| Write owned UTF-8 text to process stdin. | |
| Process & | operator<< (const StormByte::CString &str) |
| Write a CString to process stdin. | |
| void | operator<< (const System::_EoF &eof) |
| Close process stdin (write end). | |
Friends | |
| std::ostream & | operator<< (std::ostream &ostream, const Process &proc) |
| Stream process stdout to an ostream. | |
Runs an external program with piped stdin/stdout/stderr.
Starts immediately on construction. Move-only. Construction does not throw. operator bool is true only while a child is live (running or suspended). A finished, moved-from or failed spawn is false. Inspect Fault for the reason.
Supports chaining (p1 >> p2), writing stdin, reading stdout/stderr, Suspend/Resume.
|
strong |
Child-process enumerators.
Domain tag StormByte.System.Process. Zero is success.
|
strong |
Process lifecycle.
| Enumerator | |
|---|---|
| RUNNING | Running. |
| SUSPENDED | Suspended. |
| TERMINATED | Finished / cleaned up. |
|
noexcept |
Construct and start.
| prog | Executable path or name. |
| args | Argument list (not including argv[0]). |
|
noexcept |
Construct and start (moved).
| prog | Executable path or name (moved). |
| args | Argument list (moved). |
|
delete |
|
noexcept |
Move constructor (invalidates the source).
|
virtualnoexcept |
Destructor (waits if still owning a child, then frees pipes).
|
noexcept |
|
explicitnoexcept |
Whether a child is live.
| Process & StormByte::System::Process::operator<< | ( | const StormByte::CString & | str | ) |
| Process & StormByte::System::Process::operator<< | ( | const StormByte::String::String & | str | ) |
Write owned UTF-8 text to process stdin.
| str | Data. |
| void StormByte::System::Process::operator<< | ( | const System::_EoF & | eof | ) |
Close process stdin (write end).
| eof | EoF sentinel. |
| Process & StormByte::System::Process::operator<< | ( | std::string_view | str | ) |
Write UTF-8 text to process stdin.
| str | Data. |
Move assignment (invalidates the source).
Forward this process stdout to proc stdin (background thread).
| proc | Target process. |
proc. | std::string & StormByte::System::Process::operator>> | ( | std::string & | str | ) | const |
Read remaining stdout into a caller-owned string.
| str | Destination. |
str. | StormByte::String::String & StormByte::System::Process::operator>> | ( | StormByte::String::String & | str | ) | const |
Read remaining stdout into owned text.
| str | Destination. |
str.
|
noexcept |
Child PID.
| void StormByte::System::Process::Resume | ( | ) |
Resume a suspended child process.
| std::string & StormByte::System::Process::Stderr | ( | std::string & | str | ) | const |
Read remaining stderr into a caller-owned string.
| str | Destination. |
str. | StormByte::String::String & StormByte::System::Process::Stderr | ( | StormByte::String::String & | str | ) | const |
Read remaining stderr into owned text.
| str | Destination. |
str. | void StormByte::System::Process::Suspend | ( | ) |
Suspend the child process.
|
noexcept |
Block until the process exits (no timeout).
|
noexcept |
Wait for the process to exit up to timeout.
| timeout | Maximum wait duration. |
|
friend |