pub struct Command { /* private fields */ }Expand description
Structured description of an external command to run.
Command stores a program and argument vector instead of parsing a
shell-like command line. This avoids quoting ambiguity and accidental shell
injection. Use Self::shell only when shell parsing, redirection,
expansion, or pipes are intentionally required.
§Author
Haixing Hu
Implementations§
Source§impl Command
impl Command
Sourcepub fn shell(command_line: &str) -> Self
pub fn shell(command_line: &str) -> Self
Creates a command executed through the platform shell.
On Unix-like platforms this creates sh -c <command_line>. On Windows
this creates cmd /C <command_line>. Prefer Self::new with explicit
arguments when shell parsing is not required.
§Parameters
command_line- Shell command line to execute.
§Returns
A command that invokes the platform shell.
Sourcepub fn working_directory<P>(self, working_directory: P) -> Self
pub fn working_directory<P>(self, working_directory: P) -> Self
Sourcepub fn env_remove(self, key: &str) -> Self
pub fn env_remove(self, key: &str) -> Self
Sourcepub fn env_remove_os<S>(self, key: S) -> Self
pub fn env_remove_os<S>(self, key: S) -> Self
Sourcepub fn env_clear(self) -> Self
pub fn env_clear(self) -> Self
Clears all inherited environment variables for this command.
Environment variables added after this call are still passed to the child process.
§Returns
The updated command.
Sourcepub fn stdin_null(self) -> Self
pub fn stdin_null(self) -> Self
Sourcepub fn stdin_inherit(self) -> Self
pub fn stdin_inherit(self) -> Self
Sourcepub fn stdin_bytes<B>(self, bytes: B) -> Self
pub fn stdin_bytes<B>(self, bytes: B) -> Self
Sourcepub fn stdin_file<P>(self, path: P) -> Self
pub fn stdin_file<P>(self, path: P) -> Self
Sourcepub fn working_directory_override(&self) -> Option<&Path>
pub fn working_directory_override(&self) -> Option<&Path>
Returns the per-command working directory override.
§Returns
Some(path) when the command has a working directory override, or
None when the runner default should be used.
Sourcepub fn environment(&self) -> &[(OsString, OsString)]
pub fn environment(&self) -> &[(OsString, OsString)]
Returns environment variable overrides.
§Returns
Borrowed environment variable entries in insertion order.
Sourcepub fn removed_environment(&self) -> &[OsString]
pub fn removed_environment(&self) -> &[OsString]
Returns environment variable removals.
§Returns
Borrowed environment variable names removed before spawning the command.
Sourcepub const fn clears_environment(&self) -> bool
pub const fn clears_environment(&self) -> bool
Returns whether the inherited environment is cleared.
§Returns
true when the command should start from an empty environment.
Trait Implementations§
impl Eq for Command
impl StructuralPartialEq for Command
Auto Trait Implementations§
impl Freeze for Command
impl RefUnwindSafe for Command
impl Send for Command
impl Sync for Command
impl Unpin for Command
impl UnsafeUnpin for Command
impl UnwindSafe for Command
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.