Fields
id: Id,
Available after calling spawn()
. This becomes undefined
after calling wait()
. On Windows this is the hProcess. On POSIX this is the pid.
thread_handle: if (builtin.os.tag == .windows) windows.HANDLE else void,
stdin: ?File,
stdout: ?File,
stderr: ?File,
term: ?SpawnError!Term,
argv: []const []const u8,
env_map: ?*const EnvMap,
Leave as null to use the current env map using the supplied allocator.
stdin_behavior: StdIo,
stdout_behavior: StdIo,
stderr_behavior: StdIo,
Set to change the user id when spawning the child process.
Set to change the group id when spawning the child process.
cwd: ?[]const u8,
Set to change the current working directory when spawning the child process.
Set to change the current working directory when spawning the child process. This is not yet implemented for Windows. See https://github.com/ziglang/zig/issues/5190 Once that is done, cwd
will be deprecated in favor of this field.
err_pipe: ?if (builtin.os.tag == .windows) void else [2]os.fd_t,
expand_arg0: Arg0Expand,
disable_aslr: bool = false,
Darwin-only. Disable ASLR for the child process.
start_suspended: bool = false,
Darwin-only. Start child process in suspended state as if SIGSTOP was sent.
request_resource_usage_statistics: bool = false,
Set to true to obtain rusage information for the child process. Depending on the target platform and implementation status, the requested statistics may or may not be available. If they are available, then the resource_usage_statistics
field will be populated after calling wait
. On Linux and Darwin, this obtains rusage statistics from wait4().
resource_usage_statistics: ResourceUsageStatistics = .{ },
This is available after calling wait if request_resource_usage_statistics
was set to true
before calling spawn
.
Functions
fn collectOutput(child: ChildProcess, stdout: *field_call, stderr: *field_call, max_output_bytes: usize) !void
Collect the output from the process’s stdout and stderr. Will return once all ou…
Collect the output from the process’s stdout and stderr. Will return once all output has been collected. This does not mean that the process has ended.
wait
should still be called to wait for and clean up the process.The process must be started with stdout_behavior and stderr_behavior == .Pipe
fn exec(args: struct { allocator: mem.Allocator, argv: []const []const u8, cwd: ?[]const u8 = null, cwd_dir: ?fs.Dir = null, env_map: ?*const EnvMap = null, max_output_bytes: usize = 50 * 1024, expand_arg0: Arg0Expand = .no_expand, }) ExecError!ExecResult
Spawns a child process, waits for it, collecting stdout and stderr, and then ret…
Spawns a child process, waits for it, collecting stdout and stderr, and then returns. If it succeeds, the caller owns result.stdout and result.stderr memory.
fn init(argv: []const []const u8, allocator: mem.Allocator) ChildProcess
First argument in argv is the executable.
fn kill(self: *ChildProcess) !Term
Forcibly terminates child process and then cleans up all resources.
fn spawn(self: *ChildProcess) SpawnError!void
On success must call
kill
orwait
. After spawning theid
is available.fn wait(self: *ChildProcess) !Term
Blocks until child process terminates and then cleans up all resources.