std::processProcess execution.
Run external commands and manage child processes.
process.Child is an owned handle. Dropping a Child reaps the OS
process handle: if the child has already exited, drop performs the final
wait; if it is still running, drop kills it and waits for it to exit.
import std.process;
fn main() {
let shell_output = process.run("echo hello").expect("run succeeds");
println(shell_output.stdout);
var args: Vec<string> = Vec.new();
args.push("<%s>|<%s>");
args.push("hello world");
args.push("hew");
let output = process.run_argv("printf", args).expect("run_argv succeeds");
println(output.stdout);
let child = match process.start("sleep 10") {
.Ok(child) => child,
.Err(error) => panic(to_string(error)),
};
println(child.wait());
}
runRun a shell command synchronously and capture its exit code and output.
run_argvRun a command without the shell using a Vec<string> argv surface.
run_argsLegacy compatibility wrapper for a space-delimited argument string.
This packed-string surface cannot represent empty arguments, quoted
segments, or arguments containing spaces. Prefer
run_argv(command, Vec<string>).
startStart a child process through the system shell without blocking.
Returns Err(ProcessError.LaunchFailed) when the child could not be
launched, rather than a handle that is not backed by a running process.
start_argvStart a child process without the shell using a Vec<string> argv surface.
Returns Err(ProcessError.LaunchFailed) when the executable cannot be
launched โ a missing command is reported here rather than surfacing as a
handle that never referred to a process.
ProcessResultHandleA handle to a completed command invocation inside the runtime.
ChildA handle to a running child process.
Created by process.start(cmd). Use wait() to block until
the process exits, or kill() to terminate it. Dropping the
handle reaps it automatically; a still-running child is killed
and waited on at scope exit.
CommandOutputCaptured output from a completed command.
ProcessErrorStructured execution errors for process launch and argument validation.
InvalidArguments(string)LaunchFailed(string)ChildMethodsMethods available on a Child process.
Block until the child process exits and return its exit code.
Returns 0 for success, non-zero for failure.
Terminate the child process.
Returns 0 on success, non-zero on error.