DoxigAlpha

waitForSpawn

On some targets, spawn may not report all spawn errors, such as error.InvalidExe. This function will block until any spawn errors can be reported, and return them.

Function parameters

Parameters

#
self:*ChildProcess

Type definitions in this namespace

Types

#
StdIo
Behavior of the child process's standard input, output, and error
WindowsExtension
File name extensions supported natively by `CreateProcess()` on Windows.

First argument in argv is the executable.

Functions

#
init
First argument in argv is the executable.
spawn
On success must call `kill` or `wait`.
kill
Forcibly terminates child process and then cleans up all resources.
waitForSpawn
On some targets, `spawn` may not report all spawn errors, such as `error.InvalidExe`.
wait
Blocks until child process terminates and then cleans up all resources.
collectOutput
Collect the output from the process's stdout and stderr.
run
Spawns a child process, waits for it, collecting stdout and stderr, and then returns.

Error sets in this namespace

Error Sets

#

Source

Implementation

#
pub fn waitForSpawn(self: *ChildProcess) SpawnError!void {
    if (native_os == .windows) return; // `spawn` reports everything
    if (self.term) |term| {
        _ = term catch |spawn_err| return spawn_err;
        return;
    }

    const err_pipe = self.err_pipe orelse return;
    self.err_pipe = null;

    // Wait for the child to report any errors in or before `execvpe`.
    if (readIntFd(err_pipe)) |child_err_int| {
        posix.close(err_pipe);
        const child_err: SpawnError = @errorCast(@errorFromInt(child_err_int));
        self.term = child_err;
        return child_err;
    } else |_| {
        // Write end closed by CLOEXEC at the time of the `execvpe` call, indicating success!
        posix.close(err_pipe);
    }
}