pub struct Command { /* private fields */ }
Expand description
Run a CLI command and store its stdout.
§Example
#[cfg(target_os = "macos")]
let command = Command::new("uname", r#"/usr/bin/uname -a"#)
.with_title("Host OS")
.with_timeout(5);
#[cfg(target_os = "linux")]
let command = Command::new("true", r#"/bin/true"#)
.with_title("Just a successful command")
.with_timeout(5);
match command.exec() {
CommandResult::Success {
command: _,
run_time_ms: _,
stdout: stdout,
} => println!("Command output '{}'", stdout),
CommandResult::Failed {
command: _,
run_time_ms: _,
stdout: stdout,
} => println!("Command failed with output '{}'", stdout),
CommandResult::Timeout {
command: _,
run_time_ms: _,
} => println!("Command timed out"),
CommandResult::Error {
command: _,
reason: reason,
} => println!("Command errored because {}", reason),
};
Implementations§
Source§impl Command
impl Command
Sourcepub fn new<T: Into<String>>(name: T, command: T) -> Command
pub fn new<T: Into<String>>(name: T, command: T) -> Command
Create new command with default values
Sourcepub fn description(&self) -> Option<&str>
pub fn description(&self) -> Option<&str>
Get description of command
Sourcepub fn with_title<T: Into<String>>(self, title: T) -> Command
pub fn with_title<T: Into<String>>(self, title: T) -> Command
Set title of command
Sourcepub fn with_timeout<T: Into<Option<u64>>>(self, timeout_sec: T) -> Command
pub fn with_timeout<T: Into<Option<u64>>>(self, timeout_sec: T) -> Command
Set title of command
Sourcepub fn with_description<T: Into<String>, S: Into<Option<T>>>(
self,
description: S,
) -> Command
pub fn with_description<T: Into<String>, S: Into<Option<T>>>( self, description: S, ) -> Command
Set description of command
Sourcepub fn exec(self) -> CommandResult
pub fn exec(self) -> CommandResult
Execute this command; may panic
Standard output and error will be written to a temporary file, because a pipe may only contain up 64 KB data; cf. http://man7.org/linux/man-pages/man7/pipe.7.html.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Command
impl<'de> Deserialize<'de> for Command
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
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 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
Mutably borrows from an owned value. Read more