1.0.0[−][src]Struct std::process::Stdio
Describes what to do with a standard I/O stream for a child process when
passed to the stdin
, stdout
, and stderr
methods of Command
.
Methods
impl Stdio
[src][−]
pub fn piped() -> Stdio
[src][−]
A new pipe should be arranged to connect the parent and child processes.
Examples
With stdout:
use std::process::{Command, Stdio}; let output = Command::new("echo") .arg("Hello, world!") .stdout(Stdio::piped()) .output() .expect("Failed to execute command"); assert_eq!(String::from_utf8_lossy(&output.stdout), "Hello, world!\n"); // Nothing echoed to consoleRun
With stdin:
use std::io::Write; use std::process::{Command, Stdio}; let mut child = Command::new("rev") .stdin(Stdio::piped()) .stdout(Stdio::piped()) .spawn() .expect("Failed to spawn child process"); { let mut stdin = child.stdin.as_mut().expect("Failed to open stdin"); stdin.write_all("Hello, world!".as_bytes()).expect("Failed to write to stdin"); } let output = child.wait_with_output().expect("Failed to read stdout"); assert_eq!(String::from_utf8_lossy(&output.stdout), "!dlrow ,olleH\n");Run
pub fn inherit() -> Stdio
[src][−]
The child inherits from the corresponding parent descriptor.
Examples
With stdout:
use std::process::{Command, Stdio}; let output = Command::new("echo") .arg("Hello, world!") .stdout(Stdio::inherit()) .output() .expect("Failed to execute command"); assert_eq!(String::from_utf8_lossy(&output.stdout), ""); // "Hello, world!" echoed to consoleRun
With stdin:
use std::process::{Command, Stdio}; use std::io::{self, Write}; let output = Command::new("rev") .stdin(Stdio::inherit()) .stdout(Stdio::piped()) .output() .expect("Failed to execute command"); print!("You piped in the reverse of: "); io::stdout().write_all(&output.stdout).unwrap();Run
pub fn null() -> Stdio
[src][−]
This stream will be ignored. This is the equivalent of attaching the
stream to /dev/null
Examples
With stdout:
use std::process::{Command, Stdio}; let output = Command::new("echo") .arg("Hello, world!") .stdout(Stdio::null()) .output() .expect("Failed to execute command"); assert_eq!(String::from_utf8_lossy(&output.stdout), ""); // Nothing echoed to consoleRun
With stdin:
use std::process::{Command, Stdio}; let output = Command::new("rev") .stdin(Stdio::null()) .stdout(Stdio::piped()) .output() .expect("Failed to execute command"); assert_eq!(String::from_utf8_lossy(&output.stdout), ""); // Ignores any piped-in inputRun
Trait Implementations
impl FromRawFd for Stdio
1.2.0[src][+]
impl FromRawHandle for Stdio
1.2.0[src][+]
impl From<ChildStdin> for Stdio
1.20.0[src][+]
impl From<ChildStdout> for Stdio
1.20.0[src][+]
impl From<ChildStderr> for Stdio
1.20.0[src][+]
impl From<File> for Stdio
1.20.0[src][+]
impl Debug for Stdio
1.16.0[src][+]
Auto Trait Implementations
Blanket Implementations
impl<T> From<T> for T
[src][+]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src][+]
U: Into<T>,
impl<T, U> Into<U> for T where
U: From<T>,
[src][+]
U: From<T>,
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src][+]
U: TryFrom<T>,
impl<T> Borrow<T> for T where
T: ?Sized,
[src][+]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src][+]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src][+]
T: 'static + ?Sized,