Public Member Functions | List of all members
process Class Referencefinal

The process class manages an asynchronous process with redirected IO. More...

#include <process.hpp>

Public Member Functions

 process (process const &)=delete
processoperator= (process const &)=delete
bool spawn (native_string const &cmd, std::vector< native_string > const &args=std::vector< native_string >(), bool redirect_io=true)
 Start the process. More...
bool spawn (std::vector< native_string > const &command_with_args, bool redirect_io=true)
void kill ()
 Stops the spawned process. More...
int read (char *buffer, unsigned int len)
 Read data from process. More...
bool write (char const *buffer, unsigned int len)
 Write data data process. More...
bool write (std::string_view const &s)
HANDLE handle () const
 Returns the HANDLE of the process.

Detailed Description

The process class manages an asynchronous process with redirected IO.

No console window is being created.

To use, spawn the process and, since it's blocking, call read from a different thread.


Member Function Documentation

◆ kill()

void kill ( )

Stops the spawned process.

This function doesn't actually kill the process, it merely closes the pipes.

Blocks until the process has quit.

◆ read()

int read ( char *  buffer,
unsigned int  len 

Read data from process.

This function blocks

>0 Number of octets read, can be less than requested
0 on EOF
-1 on error.

◆ spawn()

bool spawn ( native_string const &  cmd,
std::vector< native_string > const &  args = std::vector< native_string >(),
bool  redirect_io = true 

Start the process.

This function takes care of properly quoting and escaping the the program's path and its arguments. Fails if process has already been spawned.

cmdThe path of the program to execute
argsThe command-line arguments for the process.
May return true even if the process cannot be started. In that case, trying to read from the process will fail with an error or EOF.

◆ write()

bool write ( char const *  buffer,
unsigned int  len 

Write data data process.

This function blocks

true if all octets have been written.
false on error.

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