std::process
Running programs (run, capture), the environment, arguments and exit.
Source: std/process.volt
Types
struct std::process::exit_status
struct exit_statushow a program ended (run_status)
| Field | |
|---|---|
code: i32 | its exit code, or 128 + signal as run gives it; on Windows a crash's is an |
signal: i32 | the signal that ended it (SIGABRT is 6, SIGSEGV 11), or 0 if it exited |
error std::process::process_error
error process_errorwhy a program couldn't be run
| Variant | |
|---|---|
SPAWN_FAILED | not found, not executable, or out of processes |
struct std::process::output
<A: std::mem::allocator = std::mem::default_allocator> struct outputwhat a program printed, and how it ended
| Field | |
|---|---|
code: i32 | exit code, or 128 + signal |
signal: i32 = 0 | the signal that ended it, or 0 if it exited (always 0 on Windows) |
out: std::string<A> | its stdout |
err: std::string<A> | its stderr |
Functions
std::process::os
fn os() -> strthe system this program was built for: "linux", "macos", "windows" or "freebsd" (what @cfg("os", ...) tests at compile time)
std::process::arch
fn arch() -> strthe CPU this program was built for: "x86_64", "aarch64", "riscv64", "x86" or "arm" (what @cfg("arch", ...) tests at compile time)
std::process::exit
fn exit(code: i32) -> neverends the program right away: scopes don't run their deletes or defers
std::process::arg_count
fn arg_count() -> usizecommand-line arguments; arg(0) is the program itself
std::process::arg
fn arg(i: usize) -> str?argument i (null past the last one)
std::process::interrupted
fn interrupted() -> boola call failed only because a signal handler ran (EINTR): try it again
std::process::env
fn env(name: str) -> str?an environment variable (valid until the environment changes)
std::process::set_env
fn set_env(name: str, value: str) -> voidset environment variable name to value, for this process and the programs it starts
std::process::unset_env
fn unset_env(name: str) -> voidremove environment variable name
std::process::exe_path
<A: std::mem::allocator = std::mem::default_allocator> fn exe_path(allocator: A = {}) -> std::string<A>?the path of this program's executable, with symlinks resolved (null if the system won't say; Linux, macOS, FreeBSD and Windows do)
std::process::cwd
<A: std::mem::allocator = std::mem::default_allocator> fn cwd(allocator: A = {}) -> std::string<A>the working directory (where relative paths start)
std::process::set_cwd
fn set_cwd(path: str) -> std::fs::fs_error!voidchange the working directory to path
std::process::run
fn run(argv: str[..]) -> process_error!i32run a program (found on PATH) and wait for it; its exit code, or 128 + signal
std::process::run_status
fn run_status(argv: str[..]) -> process_error!exit_statusrun a program (found on PATH) and wait for it: its exit code and the signal that ended it, which run folds into one code (a crash can't be told from a program exiting 139 there)
std::process::capture
<A: std::mem::allocator = std::mem::default_allocator> fn capture(argv: str[..], input: str, allocator: A = {}) -> process_error!output<A>run a program (found on PATH) with input as its stdin; waits and collects its output, in memory from allocator
std::process::windows_args
fn windows_args(argv: str[..]) -> std::stringargv as one Windows command line, each argument quoted so that the C runtime's parser (CommandLineToArgvW's rules) gives the program back the same arguments