pub struct Command { /* private fields */ }Implementations§
Source§impl Command
impl Command
pub fn new(value: impl AsRef<OsStr>) -> Self
pub fn argument(self, value: impl AsRef<OsStr>) -> Self
pub fn optional_argument(self, optional: Option<impl AsRef<OsStr>>) -> Self
Sourcepub fn option(self, name: impl AsRef<OsStr>, value: impl AsRef<OsStr>) -> Self
pub fn option(self, name: impl AsRef<OsStr>, value: impl AsRef<OsStr>) -> Self
Adds a CLI option (name + value).
ⓘ
command.option("--message", "hello")
// equivalent to: command.argument("--message").argument("hello")Sourcepub fn optional_option(
self,
name: impl AsRef<OsStr>,
value: Option<impl AsRef<OsStr>>,
) -> Self
pub fn optional_option( self, name: impl AsRef<OsStr>, value: Option<impl AsRef<OsStr>>, ) -> Self
Adds a CLI option (name + value) only if the value is Some.
ⓘ
command.optional_option("--name", optional)
// adds "--name <value>" only if optional is Somepub fn arguments<T: AsRef<OsStr>>( self, value: impl IntoIterator<Item = T>, ) -> Self
pub fn working_directory(self, dir: impl AsRef<Path>) -> Self
pub fn env(self, key: &EnvVariableName<'_>, val: impl AsRef<OsStr>) -> Self
pub fn envs<'a, I, V>(self, vars: I) -> Self
Sourcepub fn env_remove(self, key: &EnvVariableName<'_>) -> Self
pub fn env_remove(self, key: &EnvVariableName<'_>) -> Self
Remove an environment variable from the child process.
pub fn stdin_bytes(self, data: impl Into<Vec<u8>>) -> Self
Sourcepub fn spawn(self) -> Spawn
pub fn spawn(self) -> Spawn
Spawn the command as a child process.
Returns a Spawn builder to configure stdin/stdout/stderr before running.
§Example
use cmd_proc::{Command, Stdio};
use std::io::BufRead;
let mut child = Command::new("server")
.argument("--port=8080")
.spawn()
.stdin(Stdio::Piped)
.stdout(Stdio::Piped)
.stderr(Stdio::Inherit)
.run()
.unwrap();
// Read a line from stdout
let line = std::io::BufReader::new(child.stdout().unwrap())
.lines()
.next()
.unwrap()
.unwrap();
// Close stdin to signal the child to exit
drop(child.take_stdin());
child.wait().unwrap();Sourcepub fn output(self) -> Result<Output, CommandError>
pub fn output(self) -> Result<Output, CommandError>
Execute the command and return full output regardless of exit status.
Unlike stdout() and stderr(), this does not treat non-zero exit as an error.
Use this when you need to inspect both streams or handle failure cases with stderr.
Sourcepub fn status(self) -> Result<(), CommandError>
pub fn status(self) -> Result<(), CommandError>
Execute the command and return success or an error.
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