Struct

std::process::Command!

source
struct Command! { ... }

A program to run, its arguments, and how it runs: its standard streams (stdin, stdout, stderr), its environment (env, env_remove, env_clear) and its working directory (current_dir). Each argument, name and path is any byte view, copied in as it is added: a command that outlives what it was built from. It starts with this process's streams, environment and working directory.

Methods

method newsource

forall C, S where ReadBytes[C, S], Copy[S].
fn new(&cx: C, program: S) -> Command! { ... }

A command running program, found on the PATH as posix_spawnp finds it, with no arguments yet.

method argsource

forall C, S where ReadBytes[C, S], Copy[S].
fn arg(self, &cx: C, argument: S) -> Command! { ... }

The command with argument added after its other arguments.

method envsource

forall C, N, V where ReadBytes[C, N], Copy[N], ReadBytes[C, V], Copy[V].
fn env(self, &cx: C, name: N, value: V) -> Command! { ... }

The command with the environment variable name set to value for the child, after the changes made before. A name that is empty or holds an =, or a name or value holding a NUL, makes spawn fail with EINVAL. The name and the value may be different kinds of view, read under the one capability cx.

method env_removesource

forall C, S where ReadBytes[C, S], Copy[S].
fn env_remove(self, &cx: C, name: S) -> Command! { ... }

The command with the environment variable name unset for the child, after the changes made before.

method env_clearsource

fn env_clear(self) -> Command! { ... }

The command with an empty environment for the child, and none of the changes made before: only the variables env sets after this.

method current_dirsource

forall C, S where ReadBytes[C, S], Copy[S].
fn current_dir(self, &cx: C, path: S) -> Command! { ... }

The command with path as the child's working directory. A program named by a relative path with a / in it is then found from there. Where the C library cannot change a child's directory (the runtime built with KUR_LIBC_NO_ADDCHDIR), spawn fails with ENOSYS.

method stdinsource

fn stdin(self, stdio: Stdio!) -> Command! { ... }

The command with stdio as the child's standard input. A Pipe's other end is Child!::take_stdin's, for this process to write.

method stdoutsource

fn stdout(self, stdio: Stdio!) -> Command! { ... }

The command with stdio as the child's standard output. A Pipe's other end is Child!::take_stdout's, for this process to read.

method stderrsource

fn stderr(self, stdio: Stdio!) -> Command! { ... }

The command with stdio as the child's standard error. A Pipe's other end is Child!::take_stderr's, for this process to read.

method runsource

fn run(self) -> Result[Exit, Error] { ... }

Runs the program and waits for it: spawn, then Child!::wait, with their errors.

method outputsource

fn output(self) -> Result[Captured!, Error] { ... }

Runs the program to its end, capturing what it writes to its standard output and error: how it ended, and the two outputs. Child!::wait_with_output of the child spawn starts with both streams piped; its standard input is as set (this process's own, unless stdin says otherwise).

method spawnsource

fn spawn(self) -> Result[Child!, Error] { ... }

Starts the program and hands back the running child, which must be waited for. The error is what posix_spawnp reports, among them the errno of the exec that failed (ENOENT for a program not found); EINVAL when the program, an argument or an environment change holds a NUL or a name is not one; and the errno of a pipe or of opening /dev/null. The files given as streams are closed either way.

method destroysource

fn destroy(self) { ... }

Frees a command that is not run, closing the files given as its streams.