Struct command_run::Command[][src]

pub struct Command {
    pub program: PathBuf,
    pub args: Vec<OsString>,
    pub dir: Option<PathBuf>,
    pub log_to: LogTo,
    pub log_command: bool,
    pub log_output_on_error: bool,
    pub check: bool,
    pub capture: bool,
    pub combine_output: bool,
    pub clear_env: bool,
    pub env: HashMap<OsString, OsString>,
}
Expand description

A command to run in a subprocess and options for how it is run.

Some notable trait implementations:

Fields

program: PathBuf

Program path.

The path can be just a file name, in which case the $PATH is searched.

args: Vec<OsString>

Arguments passed to the program.

dir: Option<PathBuf>

Directory from which to run the program.

If not set (the default), the current working directory is used.

log_to: LogTo

Where log messages go. The default is stdout.

log_command: bool

If true (the default), log the command before running it.

log_output_on_error: bool

If true, log the output if the command exits non-zero or due to a signal. This does nothing is capture is false or if check is false. The default is false.

check: bool

If true (the default), check if the command exited successfully and return an error if not.

capture: bool

If true, capture the stdout and stderr of the command. The default is false.

combine_output: bool

If true, send stderr to stdout; the stderr field in Output will be empty. The default is false.

clear_env: bool

If false (the default), inherit environment variables from the current process.

env: HashMap<OsString, OsString>

Add or update environment variables in the child process.

Implementations

Make a new Command with the given program.

All other fields are set to the defaults.

Make a new Command with the given program and args.

All other fields are set to the defaults.

Create a Command from a whitespace-separated string. If the string is empty or all whitespace, None is returned.

This function does not do unquoting or escaping.

Append a single argument.

Append two arguments.

This is equivalent to calling add_arg twice; it is for the common case where the arguments have different types, e.g. a literal string for the first argument and a Path for the second argument.

Append multiple arguments.

Set capture to true.

Set combine_output to true.

Set the directory from which to run the program.

Set check to false.

Run the command.

If capture is true, the command’s output (stdout and stderr) is returned along with the status. If not, the stdout and stderr are empty.

If the command fails to start an error is returned. If check is set, an error is also returned if the command exits non-zero or due to a signal.

If log_command is true then the command line is logged before running it. If the command fails the error is not logged or printed, but the resulting error type implements Display and can be used for this purpose.

Format as a space-separated command line.

The program path and the arguments are converted to strings with String::from_utf8_lossy.

If any component contains characters that are not ASCII alphanumeric or in the set /-_,:.=+, the component is quoted with ' (single quotes). This is both too aggressive (unnecessarily quoting things that don’t need to be quoted) and incorrect (e.g. a single quote will itself be quoted with a single quote). This method is mostly intended for logging though, and it should work reasonably well for that.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Performs the conversion.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.