std.process
pid, args, env vars, child processes and pipes
ProcessError
Section titled “ProcessError”pub ProcessError :: errors { spawn_failed, wait_failed, exit_code_failed, command_too_long, name_too_long, read_failed,}spawn_failed: the child couldn’t be launchedwait_failed: waiting on the child failedexit_code_failed: the child’s exit code couldn’t be readcommand_too_long: command line doesn’t fit in the internal buffername_too_long: env name/value too long for the bufferread_failed: reading what the child wrote failed
current_pid
Section titled “current_pid”pub current_pid :: fn() -> u32command_line
Section titled “command_line”pub command_line :: fn(out: []u8) -> []const u8copied into out, truncated if it doesn’t fit
pub args :: fn(a: *Arena) -> [][]const u8program first, in a; windows splits like the C runtime, linux as the kernel passed
split_command_line
Section titled “split_command_line”pub split_command_line :: fn(line: []const u8, a: *Arena) -> [][]const u8windows command line split like the C runtime, in a; the program part has no escapes
get_env
Section titled “get_env”pub get_env :: fn(name: []const u8, out: []u8) -> ?[]const u8value copied into out; null if unset or it doesn’t fit
set_env
Section titled “set_env”pub set_env :: fn(name: []const u8, value: []const u8) -> boollater children see it too; linux: a process-wide overlay that get_env and spawn use
unset_env
Section titled “unset_env”pub unset_env :: fn(name: []const u8) -> boolEnvVar
Section titled “EnvVar”pub EnvVar :: struct { name: []const u8, value: []const u8,}env_vars
Section titled “env_vars”pub env_vars :: fn(a: *Arena) -> []EnvVarall vars in a, set_env/unset_env applied; linux: first 8 KB of the startup env
exe_path
Section titled “exe_path”pub exe_path :: fn(a: *Arena) -> ?[]const u8in a; null when the OS won’t say
pub Child :: struct { token: i64, stdin: i64, stdout: i64, stderr: i64,}call release when done
stdin: our end of its stdin pipe, or -1 (spawn_piped)stdout: our end of the pipe from its stdout, or -1stderr: our end of the pipe from its stderr, or -1
pub spawn :: fn(command: []const u8) -> Child ! ProcessErrorwhole command line; inherits our std handles; linux runs it via /bin/sh -c
pub wait :: fn(self: *Child) -> u32 ! ProcessErrorblocks; returns the exit code
try_wait
Section titled “try_wait”pub try_wait :: fn(self: *Child) -> ?u32 ! ProcessErrornon-blocking; null while still running
pub kill :: fn(self: *Child) -> boolforce-terminate
release
Section titled “release”pub release :: fn(self: *Child)frees the OS handle and pipes; safe to call twice
pub Pipes :: struct { stdin: bool, stdout: bool, stderr: bool,}streams to pipe; the rest stay this process’s
spawn_piped
Section titled “spawn_piped”pub spawn_piped :: fn(command: []const u8, pipes: Pipes) -> Child ! ProcessErrorlike spawn, with pipes; read while it runs, a full pipe blocks the child piping both stdout and stderr: drain one on another thread or it can deadlock
stdin_file
Section titled “stdin_file”pub stdin_file :: fn(self: *Child) -> fs::Filewritable File; closed if stdin wasn’t piped
stdout_file
Section titled “stdout_file”pub stdout_file :: fn(self: *Child) -> fs::Filereadable File, 0 at EOF; closed if stdout wasn’t piped
stderr_file
Section titled “stderr_file”pub stderr_file :: fn(self: *Child) -> fs::Fileas stdout_file
close_stdin
Section titled “close_stdin”pub close_stdin :: fn(self: *Child)child sees EOF on stdin
Output
Section titled “Output”pub Output :: struct { code: u32, stdout: []u8,}output
Section titled “output”pub output :: fn(a: *Arena, command: []const u8) -> Output ! ProcessErrorruns to completion, stdout kept in a; stdin and stderr stay ours