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
Fields
program: PathBufProgram 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: LogToWhere log messages go. The default is stdout.
log_command: boolIf true (the default), log the command before running it.
log_output_on_error: boolIf 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: boolIf true (the default), check if the command exited
successfully and return an error if not.
capture: boolIf true, capture the stdout and stderr of the
command. The default is false.
combine_output: boolIf true, send stderr to stdout; the stderr field in
Output will be empty. The default is false.
clear_env: boolIf 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 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
Auto Trait Implementations
impl RefUnwindSafe for Command
impl UnwindSafe for Command
Blanket Implementations
Mutably borrows from an owned value. Read more