Process model that facilitates process creation, management, and interaction with other processes.
- Note
- In a sandboxed environment (especially in iOS and Android) this functionality is mostly irrelevant (except
AProcess::self()
).
The AProcess class is typically used for creating, controlling, and monitoring subprocesses (including self) in a platform-independent manner. It provides a way to run external applications from within the application itself, which can be useful for tasks like running scripts, launching other programs, or automating system operations through commands.
Launching executable#
To start a process, pass the name of application you want to run and optionally provide arguments and working dir for that application. In this code snippet, we are starting another instance of the current executable with specific arguments and capturing its standard output (stdOut).
args.list << "--help";
args.list << "-a";
.args = std::move(args),
.workDir =
self.parent(),
});
p->run();
EXPECT_EQ(p->waitForExitCode(), 0);
EXPECT_TRUE(accumulator.contains("This program contains tests written using Google Test.")) << accumulator;
std::vector-like growing array for byte storage.
Definition AByteBuffer.h:31
static _< AProcess > self()
static _< AChildProcess > create(ProcessCreationInfo args)
Launches an executable.
Represents a Unicode character string.
Definition AString.h:38
static decltype(auto) connect(const Signal &signal, Object *object, Function &&function)
Connects signal to the slot of the specified object.
Definition AObject.h:86
Process arguments represented as array of strings.
Definition AProcess.h:131
We define an empty string accumulator to collect the output from the process. Then, we connect a lambda function to the stdOut
signal of the process. This lambda function converts the received buffer (a byte array) to a UTF-8 string and appends it to accumulator
.
We start the new process by calling its AProcess::run()
method, which will execute the specified application with the provided arguments in the given working directory.
We wait for the process to finish by calling waitForExitCode()
, which blocks until the process exits and returns its exit code. If the exit code is 0, it means the process completed successfully.