22#include <StormByte/system/visibility.h>
50 static constexpr const _EoF EoF = {};
67 Process(
const std::filesystem::path& prog,
const std::vector<std::string>& args = std::vector<std::string>());
74 Process(std::filesystem::path&& prog, std::vector<std::string>&& args = std::vector<std::string>());
112 pid_t Pid() noexcept;
124 PROCESS_INFORMATION Pid();
156 std::string&
Stderr(std::string& str)
const;
161 friend STORMBYTE_SYSTEM_PUBLIC std::ostream&
operator<<(std::ostream& ostream,
const Process& proc);
206 void Send(
const std::string& str);
217 void ConsumeAndForward(
Process& exec);
222 void ReleaseOwnership() noexcept;
229 std::wstring FullCommand()
const;
Runs an external program with piped stdin/stdout/stderr.
Definition process.hxx:60
PROCESS_INFORMATION m_piProcInfo
Process info.
Definition process.hxx:192
Process & operator=(const Process &proc)=delete
Copy assignment (deleted).
void operator<<(const System::_EoF &eof)
Close process stdin (write end).
std::unique_ptr< std::thread > m_forwarder
Forwarder thread.
Definition process.hxx:199
Process & operator=(Process &&proc) noexcept
Move assignment (invalidates the source).
void Suspend()
Suspend the child process.
std::unique_ptr< Pipe > m_pstdout
stdout pipe
Definition process.hxx:194
Process(const std::filesystem::path &prog, const std::vector< std::string > &args=std::vector< std::string >())
Construct and start.
Process(const Process &proc)=delete
Copy constructor (deleted).
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).
DWORD Wait() noexcept
Block until the process exits (no timeout).
Process & operator<<(const std::string &str)
Write str to process stdin.
Process(std::filesystem::path &&prog, std::vector< std::string > &&args=std::vector< std::string >())
Construct and start (moved).
Status
Process lifecycle.
Definition process.hxx:180
std::vector< std::string > m_arguments
Arguments.
Definition process.hxx:198
std::unique_ptr< Pipe > m_pstdin
stdin pipe
Definition process.hxx:195
friend STORMBYTE_SYSTEM_PUBLIC std::ostream & operator<<(std::ostream &ostream, const Process &proc)
Stream process stdout to an ostream.
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>>(Process &proc)
Forward this process stdout to proc stdin (background thread).
std::unique_ptr< Pipe > m_pstderr
stderr pipe
Definition process.hxx:196
STARTUPINFOW m_siStartInfo
Startup info.
Definition process.hxx:191
std::filesystem::path m_program
Program path.
Definition process.hxx:197
Status m_status
Current status.
Definition process.hxx:187
System module of the StormByte suite.
Definition exception.hxx:30
STORMBYTE_SYSTEM_PUBLIC std::ostream & operator<<(std::ostream &ostream, const Process &proc)
Stream process stdout to an ostream.
Forward declaration.
Definition process.hxx:45