std::process¶
Canonical process control and child-process API; std::os::exec is compatibility-only.
Items¶
| Item | Signature | Description |
|---|---|---|
Command |
type Command |
Builder for a child process: Command::new(program) then arg / args, env / env_remove / env_clear, dir, stdin / stdout / stderr (a Stdio), new_process_group, and on POSIX new_session and controlling_terminal(fd); spawn() -> Result<Child, errors::Error>, output() -> Result<Output, errors::Error> (stdout and stderr read at once, so neither pipe stalls the child), and status() -> Result<i64, errors::Error>. Rust's std::process::Command, Go's exec.Cmd. |
Stdio |
type Stdio |
Where a child's standard stream goes: Stdio::Inherit (this process's), Stdio::Null, Stdio::Piped (read or written through the Child), or Stdio::File(f) for an open fs::File. |
Child |
type Child |
A running child: id, write_stdin / write_stdin_bytes / close_stdin, read_line / read_stdout / read_stderr and the read_stdout_line / read_stderr_line / read_stdout_chunk(max) / read_stderr_chunk(max) forms (each stream may be drained from its own goroutine), wait, wait_timeout(ms), kill, and on POSIX signal(sig) and kill_group(sig) for a child started in its own process group or session. A child that has ended answers 128 plus the signal number when a signal ended it. |
run |
fn run(program: String, args: Vec<String>) -> Result<process::Output, errors::Error> |
One-shot: runs a program with args, captures stdout/stderr plus the exit code. |
run_in |
fn run_in(program: String, args: Vec<String>, dir: String, env: Vec<(String, String)>) -> Result<process::Output, errors::Error> |
run_in(program, args, dir, env): the same one-shot run with the child's working directory and environment supplied. An empty dir inherits the caller's; the env pairs override the inherited environment rather than replacing it, so a caller sets the two variables it cares about without restating PATH. |
run_inherit |
fn run_inherit(program: String, args: Vec<String>) -> Result<i64, errors::Error> |
run_inherit(program, args) -> Result<i64, errors::Error>: runs the program on this process's own standard input, output, and error - a terminal included - and answers its exit code once it ends (128 plus the signal number for one a signal ended on Unix). The goroutine parks meanwhile. Go's exec.Cmd.Run with os.Stdin, os.Stdout, and os.Stderr attached. |
spawn |
fn spawn(program: String, args: Vec<String>) -> Result<i64, errors::Error> |
Spawns a child process and returns its PID. |
spawn_piped |
fn spawn_piped(program: String, args: Vec<String>) -> Result<process::Child, errors::Error> |
Spawns a child with piped stdin/stdout; returns Result |
kill |
fn kill(pid: i64) -> bool |
Sends SIGKILL (or equivalent) to a Child. |
exit |
fn exit(code: i64) -> ! |
Exits the current process with the given status code. |
id |
fn id() -> i64 |
Returns the current process ID. |
abort |
fn abort() -> ! |
Aborts the current process without unwinding. |
signal |
fn signal(pid: i64, signum: i64) -> bool |
Sends a signal to a process by PID (POSIX). |
kill_group |
fn kill_group(pid: i64) -> bool |
Sends a signal to a process group (POSIX). |
wait_timeout |
fn wait_timeout(pid: i64, ms: i64) -> i64 |
Waits for a child with a timeout (POSIX). |
pipeline_run |
fn pipeline_run(commands: Vec<String>) -> Result<process::Output, errors::Error> |
Runs a shell-tokenised pipeline and returns captured stdout/stderr plus the final exit code. |