mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-02 07:22:42 +00:00
std::process: impl From<io::Stdout> (etc.) for Stdio
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
This commit is contained in:
parent
1bab95bf7f
commit
36295fad12
@ -1491,6 +1491,66 @@ impl From<fs::File> for Stdio {
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "stdio_from_stdio", since = "CURRENT_RUSTC_VERSION")]
|
||||
impl From<io::Stdout> for Stdio {
|
||||
/// Redirect command stdout/stderr to our stdout
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// #![feature(exit_status_error)]
|
||||
/// use std::io;
|
||||
/// use std::process::Command;
|
||||
///
|
||||
/// # fn test() -> Result<(), Box<dyn std::error::Error>> {
|
||||
/// let output = Command::new("whoami")
|
||||
// "whoami" is a command which exists on both Unix and Windows,
|
||||
// and which succeeds, producing some stdout output but no stderr.
|
||||
/// .stdout(io::stdout())
|
||||
/// .output()?;
|
||||
/// output.status.exit_ok()?;
|
||||
/// assert!(output.stdout.is_empty());
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// #
|
||||
/// # if cfg!(unix) {
|
||||
/// # test().unwrap();
|
||||
/// # }
|
||||
/// ```
|
||||
fn from(inherit: io::Stdout) -> Stdio {
|
||||
Stdio::from_inner(inherit.into())
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "stdio_from_stdio", since = "CURRENT_RUSTC_VERSION")]
|
||||
impl From<io::Stderr> for Stdio {
|
||||
/// Redirect command stdout/stderr to our stderr
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// #![feature(exit_status_error)]
|
||||
/// use std::io;
|
||||
/// use std::process::Command;
|
||||
///
|
||||
/// # fn test() -> Result<(), Box<dyn std::error::Error>> {
|
||||
/// let output = Command::new("whoami")
|
||||
/// .stdout(io::stderr())
|
||||
/// .output()?;
|
||||
/// output.status.exit_ok()?;
|
||||
/// assert!(output.stdout.is_empty());
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// #
|
||||
/// # if cfg!(unix) {
|
||||
/// # test().unwrap();
|
||||
/// # }
|
||||
/// ```
|
||||
fn from(inherit: io::Stderr) -> Stdio {
|
||||
Stdio::from_inner(inherit.into())
|
||||
}
|
||||
}
|
||||
|
||||
/// Describes the result of a process after it has terminated.
|
||||
///
|
||||
/// This `struct` is used to represent the exit status or other termination of a child process.
|
||||
|
Loading…
Reference in New Issue
Block a user