Skip to content

Process

Module: std.process
Source: std/process.zn

Usage Example

use std.process;
fn main() {
let out = Command.new("echo").arg("hello").output().unwrap();
@println("status: {}", out.status.success());
@println("stdout: {}", out.stdout.trim_end());
}
use std.process;
fn main() {
for (arg : Process.args_iter()) {
@println("{}", arg);
}
}

Stdio

Child stdio config


pub enum Stdio {
Piped,
Inherit,
Null,
}

Process

OS process: arguments, working directory and exit


Fields:

// No Fields

Methods:

pub fn args_count() i32;
pub fn args() List[String];
pub fn args_iter() ArgsIter;
pub fn exit(code: i32) never;
pub fn cwd() Result[String, IoError];

ArgsIter

Borrowed view over the process arguments, no allocation


Fields:

index: i32,

Constructors:

pub fn new() Self;

Interfaces:

  • core.iter : Iterator

ExitStatus

Child exit report


Fields:

pub exit_code: i32,
pub term_signal: i32,

Methods:

pub fn success(*const self) bool;
pub fn code(*const self) Option[i32];
pub fn signal(*const self) Option[i32];

Output

Finished child output


Fields:

pub status: ExitStatus,
pub stdout: String,
pub stderr: String,

PipeReader

Owned pipe read end, closes on drop


Fields:

pub fd: c_int,
pub handle: *void,

Methods:

pub fn read_to_string(*self, out: *String) Result[usize, IoError];

Interfaces:

  • core.ops : Drop

PipeWriter

Owned pipe write end, closes on drop


Fields:

pub fd: c_int,
pub handle: *void,

Methods:

pub fn write_all(*self, buf: []const char) Result[void, IoError];

Interfaces:

  • core.ops : Drop

Child

Child handle, wait reaps it


Fields:

pub pid: i32,
pub handle: *void,
pub in_fd: c_int,
pub out_fd: c_int,
pub err_fd: c_int,
pub win_in: *void,
pub win_out: *void,
pub win_err: *void,

Methods:

pub fn id(*const self) i32;
pub fn take_stdin(*self) Option[PipeWriter];
pub fn take_stdout(*self) Option[PipeReader];
pub fn take_stderr(*self) Option[PipeReader];
pub fn wait(*self) Result[ExitStatus, IoError];
pub fn try_wait(*self) Result[Option[ExitStatus], IoError];
pub fn kill(*self) Result[void, IoError];

Interfaces:

  • core.ops : Drop

Command

Pending spawn, chain or rebind builders


Fields:

pub program: String,
pub argv: List[String],
pub envs: List[CommandEnv],
pub env_cleared: bool,
pub cwd: String,
pub has_cwd: bool,
pub stdin_mode: Stdio,
pub stdout_mode: Stdio,
pub stderr_mode: Stdio,

Constructors:

pub fn new(program: []const char) Self;

Mutations:

pub fn arg(self, value: []const char) Self;
pub fn args(self, values: *const List[String]) Self;
pub fn env(self, key: []const char, value: []const char) Self;
pub fn env_remove(self, key: []const char) Self;
pub fn env_clear(self) Self;
pub fn current_dir(self, dir: []const char) Self;
pub fn stdin(self, mode: Stdio) Self;
pub fn stdout(self, mode: Stdio) Self;
pub fn stderr(self, mode: Stdio) Self;

Methods:

pub fn spawn(*const self) Result[Child, IoError];
pub fn status(*const self) Result[ExitStatus, IoError];
pub fn output(*self) Result[Output, IoError];