StormByte C++ Library: System module 1.0.1.9999
StormByte-System is the C++26 process and environment module of the StormByte suite.
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Attributes | Friends | List of all members
StormByte::System::Process Class Reference

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).
 
Processoperator= (const Process &proc)=delete
 Copy assignment (deleted).
 
Processoperator= (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.
 
Processoperator>> (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.
 
Processoperator<< (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.
 

Detailed Description

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).

Member Enumeration Documentation

◆ Status

enum class StormByte::System::Process::Status : unsigned short
strong

Process lifecycle.

Enumerator
RUNNING 

Running.

SUSPENDED 

Suspended.

TERMINATED 

Finished / cleaned up.

Constructor & Destructor Documentation

◆ Process() [1/2]

StormByte::System::Process::Process ( const std::filesystem::path &  prog,
const std::vector< std::string > &  args = std::vector< std::string >() 
)

Construct and start.

Parameters
progExecutable path or name.
argsArgument list (not including argv[0]).

◆ Process() [2/2]

StormByte::System::Process::Process ( std::filesystem::path &&  prog,
std::vector< std::string > &&  args = std::vector< std::string >() 
)

Construct and start (moved).

Parameters
progExecutable path or name (moved).
argsArgument list (moved).

Member Function Documentation

◆ operator<<() [1/2]

Process & StormByte::System::Process::operator<< ( const std::string &  str)

Write str to process stdin.

Parameters
strData.
Returns
*this.

◆ operator<<() [2/2]

void StormByte::System::Process::operator<< ( const System::_EoF eof)

Close process stdin (write end).

Parameters
eofEoF sentinel.

◆ operator>>() [1/2]

Process & StormByte::System::Process::operator>> ( Process proc)

Forward this process stdout to proc stdin (background thread).

Parameters
procTarget process.
Returns
Reference to proc.

◆ operator>>() [2/2]

std::string & StormByte::System::Process::operator>> ( std::string &  str) const

Read remaining stdout into str.

Parameters
strDestination string.
Returns
Reference to str.

◆ Pid()

PROCESS_INFORMATION StormByte::System::Process::Pid ( )

Windows PROCESS_INFORMATION.

Returns
Info (zeroed if moved-from).

◆ Stderr()

std::string & StormByte::System::Process::Stderr ( std::string &  str) const

Read remaining stderr into str.

Parameters
strDestination string.
Returns
Reference to str.

◆ Wait()

DWORD StormByte::System::Process::Wait ( )
noexcept

Block until the process exits (no timeout).

Returns
Exit code, or (DWORD)-1 on failure.

Friends And Related Symbol Documentation

◆ operator<<

STORMBYTE_SYSTEM_PUBLIC std::ostream & operator<< ( std::ostream &  ostream,
const Process proc 
)
friend

Stream process stdout to an ostream.

Parameters
ostreamDestination.
procProcess.
Returns
ostream.

The documentation for this class was generated from the following file: