56#include <system_error>
66 class ProcessImplementation;
126 Process(
const std::filesystem::path& prog,
const std::vector<StormByte::String::String>& args = {})
noexcept;
133 Process(std::filesystem::path&& prog, std::vector<StormByte::String::String>&& args = {})
noexcept;
158 explicit operator
bool() const noexcept;
178 int Wait(
std::chrono::milliseconds timeout) noexcept;
184 pid_t Pid() noexcept;
190 DWORD Wait() noexcept;
197 DWORD Wait(
std::chrono::milliseconds timeout) noexcept;
203 PROCESS_INFORMATION Pid();
246 return ostream << static_cast<std::string>(owned);
283 static std::string QuoteWindowsArgument(std::string_view argument);
289 std::wstring FullCommand()
const;
296 void Send(std::string_view str);
306 void ReleaseOwnership() noexcept;
311 void JoinForwarder() noexcept;
317 void StopForwarder(
bool close_source_read) noexcept;
319 std::unique_ptr<ProcessImplementation> m_implementation;
329 static constexpr const char* Name =
"StormByte.System.Process";
341 return "Executable not found";
343 return "Process creation failed";
345 return "Process permission denied";
347 return "Process is not running";
349 return "Process has already exited";
351 return "Process wait timed out";
353 return "Process pipe is broken";
355 return "Process operation canceled";
357 return "Unknown Process error";
381 struct is_error_code_enum<
StormByte::System::Process::Error>: true_type {};
Runs an external program with piped stdin/stdout/stderr.
Definition process.hxx:91
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:243
void Suspend()
Suspend the child process.
Process(std::filesystem::path &&prog, std::vector< StormByte::String::String > &&args={}) noexcept
Construct and start (moved).
Error
Child-process enumerators.
Definition process.hxx:99
@ Canceled
The operation was canceled.
@ ExecutableNotFound
The program path or name could not be resolved.
@ AlreadyExited
The child has already exited.
@ CreationFailed
The child could not be created (fork, pipe, CreateProcess)
@ TimedOut
A timed wait expired.
@ NotRunning
There is no live child for this operation.
@ Permission
The caller may not create or signal this child.
@ BrokenPipe
stdin/stdout/stderr pipe is closed or unusable
Process & operator<<(std::string_view str)
Write UTF-8 text to process stdin.
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:115
Process(const std::filesystem::path &prog, const std::vector< StormByte::String::String > &args={}) noexcept
Construct and start.
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.
StormByte::String::String & Stderr(StormByte::String::String &str) const
Read remaining stderr into owned text.
Process & operator>>(Process &proc)
Forward this process stdout to proc stdin (background thread).
StormByte::String::String & operator>>(StormByte::String::String &str) const
Read remaining stdout into owned text.
int Wait() noexcept
Block until the process exits (no timeout).
System module of the StormByte suite.
Definition device.hxx:58
static constexpr const _EoF EoF
Sentinel used as process << System::EoF to close stdin.
Definition process.hxx:77
const StormByte::Error::Category< Process::Error > & process_category() noexcept
Category singleton for Process::Error.
static std::string Message(StormByte::System::Process::Error e)
Text for one Process enumerator.
Definition process.hxx:336
Tag type to close process stdin (write end).
Definition process.hxx:72
#define STORMBYTE_SYSTEM_PUBLIC
Definition visibility.h:53