[][src]Struct command_run::Command

pub struct Command {
    pub program: PathBuf,
    pub args: Vec<OsString>,
    pub dir: Option<PathBuf>,
    pub log_command: bool,
    pub print_command: bool,
    pub check: bool,
    pub capture: bool,
    pub clear_env: bool,
    pub env: HashMap<OsString, OsString>,
}

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

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_command: bool

If true, log the command before running it. The default is false. This does nothing if the "logging" feature is not enabled.

print_command: bool

If true (the default), print the command to stdout before running it.

check: bool

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

capture: bool

If true (the default), capture the stdout and stderr of the command.

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

impl Command[src]

pub fn new<S: AsRef<OsStr>>(program: S) -> Command[src]

Make a new Command with the given program.

All other fields are set to the defaults.

pub fn with_args<I, S1, S2>(program: S1, args: I) -> Command where
    S1: AsRef<OsStr>,
    S2: AsRef<OsStr>,
    I: IntoIterator<Item = S2>, 
[src]

Make a new Command with the given program and args.

All other fields are set to the defaults.

pub fn add_arg<S: AsRef<OsStr>>(&mut self, arg: S) -> &mut Self[src]

Append a single argument.

pub fn add_args<I, S>(&mut self, args: I) -> &mut Self where
    S: AsRef<OsStr>,
    I: IntoIterator<Item = S>, 
[src]

Append multiple arguments.

pub fn run(&self) -> Result<Output, Error>[src]

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 and/or print_command is true then the command line is logged and/or printed 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.

pub fn command_line(&self) -> OsString[src]

Format as a space-separated command line.

pub fn command_line_lossy(&self) -> String[src]

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, 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

impl Clone for Command[src]

impl Debug for Command[src]

impl Default for Command[src]

impl Eq for Command[src]

impl<'_> From<&'_ Command> for Command[src]

impl PartialEq<Command> for Command[src]

impl StructuralEq for Command[src]

impl StructuralPartialEq for Command[src]

Auto Trait Implementations

impl RefUnwindSafe for Command

impl Send for Command

impl Sync for Command

impl Unpin for Command

impl UnwindSafe for Command

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.