pub struct Cmd {
pub inner: Command,
/* private fields */
}
Expand description
A fancier Command, see the crate’s top-level docs!
Fields§
§inner: Command
The inner Command, in case you need to access it
Implementations§
Source§impl Cmd
Builder APIs
impl Cmd
Builder APIs
Sourcepub fn stdout_to_stderr(&mut self) -> &mut Self
pub fn stdout_to_stderr(&mut self) -> &mut Self
Pipe stdout into stderr
This is useful for cases where you want your program to livestream the output of a command to give your user realtime feedback, but the command randomly writes some things to stdout, and you don’t want your own stdout tainted.
If the the “stdout_to_stderr_modern” feature is enabled, this will just do
command.stdout(std::io::stderr());
, which will actually let the two streams
interleave and ideally do the best possible thing. In the future this will be
enabled by default (once the MSRV is acceptable).
Otherwise, it will use a polyfilled implementation for output
and status
that captures child stdout and prints it to the parent stderr at the end. If
using status
, command.stderr(std::io::Inherit)
will be forced on, ignoring
your own settings for stderr.
Sourcepub fn log(&mut self, strategy: impl Into<Option<LogStrategy>>) -> &mut Self
pub fn log(&mut self, strategy: impl Into<Option<LogStrategy>>) -> &mut Self
Set how executions of this command should logged, accepting:
- tracing:
tracing::Level
(the default, set to `tracing::Level::INFO``) - stdout:
std::io::Stdout
- stderr:
std::io::Stderr
- not at all:
None
You can explicitly invoke the selected logging with Cmd::log_command
Sourcepub fn check(&mut self, checked: bool) -> &mut Self
pub fn check(&mut self, checked: bool) -> &mut Self
Set whether Status::success
should be checked after executions
(except spawn
, which doesn’t yet have a Status to check).
Defaults to true
.
If true, an Err will be produced by those execution commands.
Executions which produce status will pass them to Cmd::maybe_check_status
,
which uses this setting.
Source§impl Cmd
Execution APIs
impl Cmd
Execution APIs
Sourcepub fn run(&mut self) -> Result<()>
pub fn run(&mut self) -> Result<()>
Equivalent to Cmd::status
,
but doesn’t bother returning the actual status code (because it’s captured in the Result)
Sourcepub fn spawn(&mut self) -> Result<Child>
pub fn spawn(&mut self) -> Result<Child>
Equivalent to std::process::Command::spawn
,
but logged and with the error wrapped.
Sourcepub fn output(&mut self) -> Result<Output>
pub fn output(&mut self) -> Result<Output>
Equivalent to std::process::Command::output
,
but logged, with the error wrapped, and status checked (by default)
Sourcepub fn status(&mut self) -> Result<ExitStatus>
pub fn status(&mut self) -> Result<ExitStatus>
Equivalent to std::process::Command::status
but logged, with the error wrapped, and status checked (by default)
Source§impl Cmd
Transparently forwarded std::process::Command
APIs
impl Cmd
Transparently forwarded std::process::Command
APIs
Sourcepub fn arg<S: AsRef<OsStr>>(&mut self, arg: S) -> &mut Self
pub fn arg<S: AsRef<OsStr>>(&mut self, arg: S) -> &mut Self
Forwards to std::process::Command::arg
Sourcepub fn env<K, V>(&mut self, key: K, val: V) -> &mut Self
pub fn env<K, V>(&mut self, key: K, val: V) -> &mut Self
Forwards to std::process::Command::env
Sourcepub fn envs<I, K, V>(&mut self, vars: I) -> &mut Self
pub fn envs<I, K, V>(&mut self, vars: I) -> &mut Self
Forwards to std::process::Command::envs
Sourcepub fn env_remove<K: AsRef<OsStr>>(&mut self, key: K) -> &mut Self
pub fn env_remove<K: AsRef<OsStr>>(&mut self, key: K) -> &mut Self
Forwards to std::process::Command::env_remove
Sourcepub fn env_clear(&mut self) -> &mut Self
pub fn env_clear(&mut self) -> &mut Self
Forwards to std::process::Command::env_clear
Sourcepub fn current_dir<P: AsRef<Path>>(&mut self, dir: P) -> &mut Self
pub fn current_dir<P: AsRef<Path>>(&mut self, dir: P) -> &mut Self
Forwards to std::process::Command::current_dir
Sourcepub fn stdin<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Self
pub fn stdin<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Self
Forwards to std::process::Command::stdin
Sourcepub fn stdout<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Self
pub fn stdout<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Self
Forwards to std::process::Command::stdout
Sourcepub fn stderr<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Self
pub fn stderr<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Self
Forwards to std::process::Command::stderr
Sourcepub fn get_program(&self) -> &OsStr
pub fn get_program(&self) -> &OsStr
Forwards to std::process::Command::get_program
Sourcepub fn get_args(&self) -> CommandArgs<'_>
pub fn get_args(&self) -> CommandArgs<'_>
Forwards to std::process::Command::get_args
Sourcepub fn get_envs(&self) -> CommandEnvs<'_>
pub fn get_envs(&self) -> CommandEnvs<'_>
Forwards to std::process::Command::get_envs
Sourcepub fn get_current_dir(&self) -> Option<&Path>
pub fn get_current_dir(&self) -> Option<&Path>
Forwards to std::process::Command::get_current_dir
Source§impl Cmd
Diagnostic APIs (used internally, but available for yourself)
impl Cmd
Diagnostic APIs (used internally, but available for yourself)
Sourcepub fn check_status(&self, status: ExitStatus) -> Result<()>
pub fn check_status(&self, status: ExitStatus) -> Result<()>
Check Status::success
, producing a contextful Error if it’s false
.`
Sourcepub fn maybe_check_status(&self, status: ExitStatus) -> Result<()>
pub fn maybe_check_status(&self, status: ExitStatus) -> Result<()>
Invoke Cmd::check_status
if Cmd::check
is true
(defaults to true
).
Sourcepub fn log_command(&self)
pub fn log_command(&self)
Log the current Command using the method specified by Cmd::log
(defaults to tracing::info!
).