Module std::process

Process 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.

Examples

import std::process;

fn main() {
    let shell_output = process.run("echo hello");
    println(shell_output);

    let args: Vec<string> = Vec::new();
    args.push("<%s>|<%s>");
    args.push("hello world");
    args.push("hew");
    let output = process.run_argv("printf", args);
    println(output.stdout);

    let child = process.start("sleep 10");
    println(child.wait());
}

Contents

Functions

Function try_run

pub fn try_run(command: string) -> Result<CommandOutput, ProcessError>

Run a shell command synchronously and capture its exit code and output.

Function run

pub fn run(command: string) -> string

Run a shell command synchronously and return its stdout as a string.

Blocks until the command completes. The command is executed via the system shell.

Function try_run_argv

pub fn try_run_argv(command: string, args: Vec<string>) -> Result<CommandOutput, ProcessError>

Run a command without the shell using a Vec<string> argv surface.

Function run_argv

pub fn run_argv(command: string, args: Vec<string>) -> CommandOutput

Run a command without the shell using a Vec<string> argv surface.

Panics on launch or argument errors. Use try_run_argv for Result-based error handling.

Function try_run_args

pub fn try_run_args(command: string, args: string, arg_count: i64) -> Result<CommandOutput, ProcessError>

Legacy compatibility wrapper for a space-delimited argument string.

This packed-string surface cannot represent empty arguments, quoted segments, or arguments containing spaces. Prefer try_run_argv(command, Vec<string>).

Function run_args

pub fn run_args(command: string, args: string, arg_count: i64) -> string

Legacy compatibility wrapper for run_args(command, args, arg_count).

Prefer run_argv(command, Vec<string>) for safe argument passing.

Function start

pub fn start(command: string) -> Child

Start a child process without blocking.

Returns a Child handle that can be waited on or killed.

Note: This function is called start rather than spawn because spawn is a reserved keyword in Hew (used for spawning actors).

Types

Struct ProcessResultHandle

A handle to a completed command invocation inside the runtime.

Struct Child

A 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.

Struct CommandOutput

Captured output from a completed command.

Fields

exit_code: i64
stdout: string
stderr: string

Enum ProcessError

Structured execution errors for process launch and argument validation.

Variants

InvalidArguments(string)
LaunchFailed(string)

Traits

Trait ChildMethods

Methods available on a Child process.

Methods

fn wait(self: Self) -> i64

Block until the child process exits and return its exit code.

Returns 0 for success, non-zero for failure.

fn kill(self: Self) -> i64

Terminate the child process.

Returns 0 on success, non-zero on error.