vkmEngine 1.0.15
A C++ game engine · vkmengine.com
Loading...
Searching...
No Matches
Vkm::Engine::ChildProcess Class Reference

A program run in the background, its output collected as it arrives. More...

#include <child_process.h>

Public Member Functions

bool start (const std::filesystem::path &program, const std::vector< std::string > &args, const std::filesystem::path &workingDir={})
 Start program with args in workingDir, ending any program started before.
void stop ()
 End the program and everything it started, and wait for it.
std::string takeOutput ()
 Take the output that arrived since the last call.
bool running ()
 Whether a program was started and has not yet exited.
int exitCode ()
 How the last program exited.

Detailed Description

A program run in the background, its output collected as it arrives.

Standard output and error share one pipe, read on a thread of the process's own, so a caller polls output() and finished() from its frame. stop() ends the program and everything it started - a build's compilers included - so nothing outlives it. Should this process die without stopping it, the program is ended too: on Windows with all it started, its job's; on Linux it alone is sent SIGTERM, and what it started is its own to end. Linux sends it when the thread that started the program ends, so start one from a thread that lives as long as it should.

Member Function Documentation

◆ start()

bool Vkm::Engine::ChildProcess::start ( const std::filesystem::path & program,
const std::vector< std::string > & args,
const std::filesystem::path & workingDir = {} )

Start program with args in workingDir, ending any program started before.

Parameters
programThe executable, by path.
argsIts arguments, each passed as one argument.
workingDirWhere it runs; empty keeps this process's.
Returns
Whether it started; a failure is in output().

◆ takeOutput()

std::string Vkm::Engine::ChildProcess::takeOutput ( )

Take the output that arrived since the last call.

Returns
Text as the program wrote it, possibly ending mid-line.

◆ running()

bool Vkm::Engine::ChildProcess::running ( )

Whether a program was started and has not yet exited.

Returns
True while it runs.

◆ exitCode()

int Vkm::Engine::ChildProcess::exitCode ( )

How the last program exited.

Returns
Its exit code; -1 while it runs, when none started, or when it was stopped.

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