Standard library
Process
Args, environment, spawn, capture, and process pipes.
Introduction
Args, environment, spawn, capture, and process pipes. Import std/process to bind the module as process. Call free functions as process.name(...). Struct methods use a receiver value.
/ std/process
This page is the package reference for std/process. Private helpers used only by co-located tests are not listed.
Functions
Free functions on process. Each function has a short description, an example, then parameters and return shape.
args
Returns the process argument list. Index 0 is the program name when present. Call form: process.args().
/ std/process
$ argv = process.args()
Parameters: No parameters. Returns: List of argument strings.
env
Looks up an environment variable. Call form: process.env(name).
/ std/process
| process.env("PATH") {
$ v { }
: { }
}Parameters: name: environment variable name. Returns: Option. Some arm: string value. None arm: variable unset.
env_set
Sets an environment variable for the process. Call form: process.env_set(name, value).
/ std/process
process.env_set("ECHO_DEMO", "1")Parameters: name: variable name. value: string value. Returns: None.
env_unset
Removes an environment variable from the process. Call form: process.env_unset(name).
/ std/process
process.env_unset("ECHO_DEMO")Parameters: name: variable name. Returns: None.
exit
Terminates the process with the given status code. Call form: process.exit(code).
/ std/process
; process.exit(0)
Parameters: code: process exit code. Returns: None. Does not return on success.
run
Spawns program with args and waits for exit. Call form: process.run(program, args).
/ std/process
| process.run("true", []) {
$ code { }
! e { }
}Parameters: program: executable path or name. args: list of argument strings. Returns: Result. Ok arm: integer exit status. Err arm: "failed to spawn process".
run_capture
Spawns program with args, waits, and captures stdout and stderr. Call form: process.run_capture(program, args).
/ std/process
| process.run_capture("echo", ["hi"]) {
$ r { }
! e { }
}Parameters: program: executable path or name. args: list of argument strings. Returns: Result. Ok arm: product with code, stdout, and stderr. Err arm: "failed to spawn process".
run_cwd
Spawns program with args in working directory cwd and captures output. Call form: process.run_cwd(program, args, cwd).
/ std/process
| process.run_cwd("pwd", [], ".") {
$ r { }
! e { }
}Parameters: program: executable. args: argument list. cwd: working directory (empty inherits). Returns: Result. Ok arm: product with code, stdout, stderr. Err arm: "failed to spawn process".
spawn_pipes
Spawns program with piped stdin, stdout, and stderr. Call form: process.spawn_pipes(program, args).
/ std/process
| process.spawn_pipes("cat", []) {
$ r { }
! e { }
}Parameters: program: executable. args: argument list. Returns: Result. Ok arm: product with child and pipe handles. Err arm: "failed to spawn process".
pipe_write
Writes data to a child pipe handle. Call form: process.pipe_write(pipe, data).
/ std/process
$ n = process.pipe_write(handle, "hi\n")
Parameters: handle: pipe handle. data: bytes or string. Returns: Integer bytes written, or failure status.
pipe_read
Reads bytes from a child pipe handle. Call form: process.pipe_read(pipe, limit).
/ std/process
$ b = process.pipe_read(handle, 4096)
Parameters: handle: pipe handle. limit: maximum bytes. Returns: Bytes read from the pipe.
pipe_close
Closes a child pipe handle. Call form: process.pipe_close(pipe).
/ std/process
process.pipe_close(handle)
Parameters: handle: pipe handle. Returns: None.
wait
Waits for a spawned child to exit. Call form: process.wait(child).
/ std/process
$ code = process.wait(child)
Parameters: child: child process handle. Returns: Integer exit status.