Home
Base module

Process

Spawns and manages a child process with stdin/stdout/stderr pipes.

Process

#include <icy/process.h>
class Process

Defined in src/base/include/icy/process.h:32

Spawns and manages a child process with stdin/stdout/stderr pipes.

List of all members

NameKindOwner
filevariableDeclared here
cwdvariableDeclared here
argsvariableDeclared here
envvariableDeclared here
onstdoutvariableDeclared here
onstderrvariableDeclared here
onexitvariableDeclared here
optionsvariableDeclared here
ProcessfunctionDeclared here
ProcessfunctionDeclared here
~ProcessfunctionDeclared here
ProcessfunctionDeclared here
operator=functionDeclared here
ProcessfunctionDeclared here
operator=functionDeclared here
spawnfunctionDeclared here
killfunctionDeclared here
pidfunctionDeclared here
infunctionDeclared here
outfunctionDeclared here
errfunctionDeclared here
_handlevariableDeclared here
_stdinvariableDeclared here
_stdoutvariableDeclared here
_stderrvariableDeclared here
_stdiovariableDeclared here
_cargsvariableDeclared here
_cenvvariableDeclared here
initfunctionDeclared here

Public Attributes

ReturnNameDescription
std::stringfilePath to the program to execute. Convenience proxy for options.file. Must be set before [spawn()](#spawn)
std::stringcwdSet the current working directory. Convenience proxy for options.cwd. Must be set before [spawn()](#spawn)
std::vector< std::string >argsCommand line arguments to pass to the process. Convenience proxy for options.args. Must be set before [spawn()](#spawn)
std::vector< std::string >envEnvironment variables for the process. Each entry should be in "KEY=VALUE" format. If empty, the child inherits the parent environment. Must be set before [spawn()](#spawn)
std::function< void(std::string)>onstdoutStdout callback. Called when a line has been output from the process.
std::function< void(std::string)>onstderrStderr callback. Called when a line has been output on stderr.
std::function< void(std::int64_t)>onexitExit callback. Called with process exit status code.
ProcessOptionsoptionsLibUV C options. Available for advanced use cases.

file

std::string file

Defined in src/base/include/icy/process.h:55

Path to the program to execute. Convenience proxy for options.file. Must be set before [spawn()](#spawn)


cwd

std::string cwd

Defined in src/base/include/icy/process.h:60

Set the current working directory. Convenience proxy for options.cwd. Must be set before [spawn()](#spawn)


args

std::vector< std::string > args

Defined in src/base/include/icy/process.h:65

Command line arguments to pass to the process. Convenience proxy for options.args. Must be set before [spawn()](#spawn)


env

std::vector< std::string > env

Defined in src/base/include/icy/process.h:71

Environment variables for the process. Each entry should be in "KEY=VALUE" format. If empty, the child inherits the parent environment. Must be set before [spawn()](#spawn)


onstdout

std::function< void(std::string)> onstdout

Defined in src/base/include/icy/process.h:97

Stdout callback. Called when a line has been output from the process.


onstderr

std::function< void(std::string)> onstderr

Defined in src/base/include/icy/process.h:101

Stderr callback. Called when a line has been output on stderr.


onexit

std::function< void(std::int64_t)> onexit

Defined in src/base/include/icy/process.h:105

Exit callback. Called with process exit status code.


options

ProcessOptions options

Defined in src/base/include/icy/process.h:109

LibUV C options. Available for advanced use cases.

Public Methods

ReturnNameDescription
ProcessConstructs a [Process](#process-3) attached to the given event loop.
ProcessConstructs a [Process](#process-3) with initial command-line arguments.
~ProcessDestructor.
ProcessDeleted constructor.
ProcessDeleted constructor.
voidspawnSpawns the process. Options must be properly set. Throws an exception on error.
boolkillSends a signal to the process.
intpid constReturns the process PID, or 0 if not spawned.
Pipe &inReturns the stdin pipe.
Pipe &outReturns the stdout pipe.
Pipe &errReturns the stderr pipe.

Process

Process(uv::Loop * loop = uv::defaultLoop())

Defined in src/base/include/icy/process.h:37

Constructs a [Process](#process-3) attached to the given event loop.

Parameters

  • loop Event loop to use for I/O and exit notifications. Defaults to the default loop.

Process

Process(std::initializer_list< std::string > args, uv::Loop * loop = uv::defaultLoop())

Defined in src/base/include/icy/process.h:42

Constructs a [Process](#process-3) with initial command-line arguments.

Parameters

  • args Initializer list of argument strings. The first element is typically the executable path.

  • loop Event loop to use for I/O and exit notifications. Defaults to the default loop.


~Process

~Process()

Defined in src/base/include/icy/process.h:45

Destructor.


Process

Process(const Process &) = delete

Defined in src/base/include/icy/process.h:47

Deleted constructor.


Process

Process(Process &&) = delete

Defined in src/base/include/icy/process.h:49

Deleted constructor.


spawn

void spawn()

Defined in src/base/include/icy/process.h:76

Spawns the process. Options must be properly set. Throws an exception on error.


kill

bool kill(int signum = SIGTERM)

Defined in src/base/include/icy/process.h:81

Sends a signal to the process.

Parameters

  • signum Signal number to send (default: SIGTERM).

Returns

True if the signal was sent successfully, false if the process is not running or handle is invalid.


pid

const

int pid() const

Defined in src/base/include/icy/process.h:84

Returns the process PID, or 0 if not spawned.


in

Pipe & in()

Defined in src/base/include/icy/process.h:87

Returns the stdin pipe.


out

Pipe & out()

Defined in src/base/include/icy/process.h:90

Returns the stdout pipe.


err

Pipe & err()

Defined in src/base/include/icy/process.h:93

Returns the stderr pipe.

Protected Attributes

ReturnNameDescription
uv::Handle< uv_process_t >_handle
Pipe_stdin
Pipe_stdout
Pipe_stderr
uv_stdio_container_t_stdio
std::vector< char * >_cargs
std::vector< char * >_cenv

_handle

uv::Handle< uv_process_t > _handle

Defined in src/base/include/icy/process.h:114


_stdin

Pipe _stdin

Defined in src/base/include/icy/process.h:115


_stdout

Pipe _stdout

Defined in src/base/include/icy/process.h:116


_stderr

Pipe _stderr

Defined in src/base/include/icy/process.h:117


_stdio

uv_stdio_container_t _stdio

Defined in src/base/include/icy/process.h:118


_cargs

std::vector< char * > _cargs

Defined in src/base/include/icy/process.h:119


_cenv

std::vector< char * > _cenv

Defined in src/base/include/icy/process.h:120

Protected Methods

ReturnNameDescription
voidinit

init

void init()

Defined in src/base/include/icy/process.h:112