43#include <StormByte/error.hxx>
44#include <StormByte/safe/pointers.hxx>
45#include <StormByte/safe/string.hxx>
46#include <StormByte/safe/vector.hxx>
53#include <system_error>
62 class ProcessImplementation;
148 explicit operator
bool() const noexcept;
168 int Wait(
std::chrono::milliseconds timeout) noexcept;
180 DWORD
Wait() noexcept;
187 DWORD
Wait(
std::chrono::milliseconds timeout) noexcept;
193 DWORD
Pid() noexcept;
236 return ostream << static_cast<std::string>(owned);
259 static std::string QuoteWindowsArgument(std::string_view argument);
265 std::wstring FullCommand()
const;
272 void Send(std::string_view str);
289 void ReleaseOwnership() noexcept;
294 void JoinForwarder() noexcept;
300 void StopForwarder(
bool close_source_read) noexcept;
302 StormByte::
Safe::Unique<ProcessImplementation> m_implementation;
312 static constexpr const char*
Name =
"StormByte.System.Process";
324 return "Executable not found";
326 return "Process creation failed";
328 return "Process permission denied";
330 return "Process is not running";
332 return "Process has already exited";
334 return "Process wait timed out";
336 return "Process pipe is broken";
338 return "Process operation canceled";
340 return "Process operation failed";
342 return "Unknown Process error";
369 struct is_error_code_enum<
StormByte::System::Process::Error>: true_type {};
Runs an external program with piped stdin/stdout/stderr.
Definition process.hxx:87
Process & operator=(const Process &proc)=delete
void operator<<(const System::_EoF &eof)
Close process stdin (write end).
Process & operator=(Process &&proc) noexcept
Move assignment (invalidates the source).
STORMBYTE_FORCE_INLINE friend std::ostream & operator<<(std::ostream &ostream, const Process &proc)
Stream process stdout to an ostream.
Definition process.hxx:233
void Suspend()
Suspend the child process.
Error
Child-process enumerators.
Definition process.hxx:95
@ Canceled
The operation was canceled.
Definition process.hxx:104
@ ExecutableNotFound
The program path or name could not be resolved.
Definition process.hxx:97
@ AlreadyExited
The child has already exited.
Definition process.hxx:101
@ Success
No error.
Definition process.hxx:96
@ CreationFailed
The child could not be created (fork, pipe, CreateProcess).
Definition process.hxx:98
@ TimedOut
A timed wait expired.
Definition process.hxx:102
@ OperationFailed
A process operation failed at the platform boundary.
Definition process.hxx:105
@ NotRunning
There is no live child for this operation.
Definition process.hxx:100
@ Permission
The caller may not create or signal this child.
Definition process.hxx:99
@ BrokenPipe
stdin/stdout/stderr pipe is closed or unusable
Definition process.hxx:103
Process & operator<<(std::string_view str)
Write UTF-8 text to process stdin.
StormByte::Error::Fault Fault() const noexcept
Last Process error.
Process(const Process &proc)=delete
Process(Process &&proc) noexcept
Move constructor (invalidates the source).
void Resume()
Resume a suspended child process.
virtual ~Process() noexcept
Destructor (waits if still owning a child, then frees pipes).
Status
Process lifecycle.
Definition process.hxx:112
StormByte::Safe::String & Stderr(StormByte::Safe::String &str) const
Read remaining stderr into owned text.
pid_t Pid() noexcept
Child PID.
StormByte::Safe::String & operator>>(StormByte::Safe::String &str) const
Read remaining stdout into owned text.
Process & operator>>(Process &proc)
Forward this process stdout to proc stdin (background thread).
int Wait() noexcept
Block until the process exits (no timeout).
Process(std::string_view prog, const StormByte::Safe::Vector< StormByte::Safe::String > &args={}) noexcept
Construct and start.
System module of the StormByte suite.
Definition device.hxx:59
STORMBYTE_FORCE_INLINE std::error_code make_error_code(Device::Error e) noexcept
Builds an std::error_code from Device::Error.
Definition device.hxx:341
static constexpr const _EoF EoF
Sentinel used as process << System::EoF to close stdin.
Definition process.hxx:73
const StormByte::Error::Category< Process::Error > & process_category() noexcept
Category singleton for Process::Error.
static STORMBYTE_FORCE_INLINE std::string Message(StormByte::System::Process::Error e)
Text for one Process enumerator.
Definition process.hxx:319
static constexpr const char * Name
Stable category tag.
Definition process.hxx:312
Tag type to close process stdin (write end).
Definition process.hxx:68
#define STORMBYTE_SYSTEM_PUBLIC
Definition visibility.h:53