|
StormByte C++ Library: System module 1.0.1.9999
StormByte-System is the C++26 process and environment module of the StormByte suite.
|
Runs an external program with piped stdin/stdout/stderr. More...
#include <process.hxx>
Public Types | |
| enum class | Status : unsigned short { RUNNING , SUSPENDED , TERMINATED } |
| Process lifecycle. More... | |
Public Member Functions | |
| Process (const std::filesystem::path &prog, const std::vector< std::string > &args=std::vector< std::string >()) | |
| Construct and start. | |
| Process (std::filesystem::path &&prog, std::vector< std::string > &&args=std::vector< std::string >()) | |
| Construct and start (moved). | |
| Process (const Process &proc)=delete | |
| Copy constructor (deleted). | |
| Process (Process &&proc) noexcept | |
| Move constructor (invalidates the source). | |
| Process & | operator= (const Process &proc)=delete |
| Copy assignment (deleted). | |
| Process & | operator= (Process &&proc) noexcept |
| Move assignment (invalidates the source). | |
| virtual | ~Process () noexcept |
| Destructor (waits if still owning a child, then frees pipes). | |
| DWORD | Wait () noexcept |
| Block until the process exits (no timeout). | |
| PROCESS_INFORMATION | Pid () |
| Windows PROCESS_INFORMATION. | |
| 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 str. | |
| std::string & | Stderr (std::string &str) const |
Read remaining stderr into str. | |
| Process & | operator<< (const std::string &str) |
Write str to process stdin. | |
| void | operator<< (const System::_EoF &eof) |
| Close process stdin (write end). | |
Protected Attributes | |
| Status | m_status |
| Current status. | |
| STARTUPINFOW | m_siStartInfo |
| Startup info. | |
| PROCESS_INFORMATION | m_piProcInfo |
| Process info. | |
| std::unique_ptr< Pipe > | m_pstdout |
| stdout pipe | |
| std::unique_ptr< Pipe > | m_pstdin |
| stdin pipe | |
| std::unique_ptr< Pipe > | m_pstderr |
| stderr pipe | |
| std::filesystem::path | m_program |
| Program path. | |
| std::vector< std::string > | m_arguments |
| Arguments. | |
| std::unique_ptr< std::thread > | m_forwarder |
| Forwarder thread. | |
Friends | |
| STORMBYTE_SYSTEM_PUBLIC 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. Supports chaining (p1 >> p2), writing stdin, reading stdout/stderr, Suspend/Resume. Wait() blocks until exit (no timeout).
|
strong |
Process lifecycle.
| Enumerator | |
|---|---|
| RUNNING | Running. |
| SUSPENDED | Suspended. |
| TERMINATED | Finished / cleaned up. |
| StormByte::System::Process::Process | ( | const std::filesystem::path & | prog, |
| const std::vector< std::string > & | args = std::vector< std::string >() |
||
| ) |
Construct and start.
| prog | Executable path or name. |
| args | Argument list (not including argv[0]). |
| StormByte::System::Process::Process | ( | std::filesystem::path && | prog, |
| std::vector< std::string > && | args = std::vector< std::string >() |
||
| ) |
Construct and start (moved).
| prog | Executable path or name (moved). |
| args | Argument list (moved). |
| Process & StormByte::System::Process::operator<< | ( | const std::string & | str | ) |
Write str to process stdin.
| str | Data. |
| void StormByte::System::Process::operator<< | ( | const System::_EoF & | eof | ) |
Close process stdin (write end).
| eof | EoF sentinel. |
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 str.
| str | Destination string. |
str. | PROCESS_INFORMATION StormByte::System::Process::Pid | ( | ) |
Windows PROCESS_INFORMATION.
| std::string & StormByte::System::Process::Stderr | ( | std::string & | str | ) | const |
Read remaining stderr into str.
| str | Destination string. |
str.
|
noexcept |
Block until the process exits (no timeout).
|
friend |