pub struct 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
.
impl Stdio
[src]
pub fn piped() -> Stdio
[src]
A new pipe should be arranged to connect the parent and child processes.
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 console
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 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");
pub fn inherit() -> Stdio
[src]
The child inherits from the corresponding parent descriptor.
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 console
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();
pub fn null() -> Stdio
[src]
This stream will be ignored. This is the equivalent of attaching the stream to /dev/null
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 console
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 input
impl Debug for Stdio
[src]1.16.0
impl From<ChildStderr> for Stdio
[src]1.20.0
fn from(child: ChildStderr) -> Stdio
[src]
Converts a ChildStderr
into a Stdio
use std::process::{Command, Stdio}; let reverse = Command::new("rev") .arg("non_existing_file.txt") .stderr(Stdio::piped()) .spawn() .expect("failed reverse command"); let cat = Command::new("cat") .arg("-") .stdin(reverse.stderr.unwrap()) // Converted into a Stdio here .output() .expect("failed echo command"); assert_eq!( String::from_utf8_lossy(&cat.stdout), "rev: cannot open non_existing_file.txt: No such file or directory\n" );
impl From<ChildStdin> for Stdio
[src]1.20.0
fn from(child: ChildStdin) -> Stdio
[src]
Converts a ChildStdin
into a Stdio
ChildStdin
will be converted to Stdio
using Stdio::from
under the hood.
use std::process::{Command, Stdio}; let reverse = Command::new("rev") .stdin(Stdio::piped()) .spawn() .expect("failed reverse command"); let _echo = Command::new("echo") .arg("Hello, world!") .stdout(reverse.stdin.unwrap()) // Converted into a Stdio here .output() .expect("failed echo command"); // "!dlrow ,olleH" echoed to console
impl From<ChildStdout> for Stdio
[src]1.20.0
fn from(child: ChildStdout) -> Stdio
[src]
Converts a ChildStdout
into a Stdio
ChildStdout
will be converted to Stdio
using Stdio::from
under the hood.
use std::process::{Command, Stdio}; let hello = Command::new("echo") .arg("Hello, world!") .stdout(Stdio::piped()) .spawn() .expect("failed echo command"); let reverse = Command::new("rev") .stdin(hello.stdout.unwrap()) // Converted into a Stdio here .output() .expect("failed reverse command"); assert_eq!(reverse.stdout, b"!dlrow ,olleH\n");
impl From<File> for Stdio
[src]1.20.0
fn from(file: File) -> Stdio
[src]
Converts a File
into a Stdio
File
will be converted to Stdio
using Stdio::from
under the hood.
use std::fs::File; use std::process::Command; // With the `foo.txt` file containing `Hello, world!" let file = File::open("foo.txt").unwrap(); let reverse = Command::new("rev") .stdin(file) // Implicit File conversion into a Stdio .output() .expect("failed reverse command"); assert_eq!(reverse.stdout, b"!dlrow ,olleH");
impl FromRawFd for Stdio
[src]1.2.0
unsafe fn from_raw_fd(fd: RawFd) -> Stdio
[src]
impl FromRawHandle for Stdio
[src]1.2.0
unsafe fn from_raw_handle(handle: RawHandle) -> Stdio
[src]
impl RefUnwindSafe for Stdio
impl Send for Stdio
impl Sync for Stdio
impl Unpin for Stdio
impl UnwindSafe for Stdio
impl<T> Any for T where
T: 'static + ?Sized,
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
fn borrow(&self) -> &TⓘNotable traits for &'_ mut F
impl<'_, F> Future for &'_ mut F where
F: Unpin + Future + ?Sized,
type Output = <F as Future>::Output;
impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized,
type Item = <I as Iterator>::Item;
impl<R: Read + ?Sized, '_> Read for &'_ mut R
impl<W: Write + ?Sized, '_> Write for &'_ mut W
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
fn borrow_mut(&mut self) -> &mut TⓘNotable traits for &'_ mut F
impl<'_, F> Future for &'_ mut F where
F: Unpin + Future + ?Sized,
type Output = <F as Future>::Output;
impl<'_, I> Iterator for &'_ mut I where
I: Iterator + ?Sized,
type Item = <I as Iterator>::Item;
impl<R: Read + ?Sized, '_> Read for &'_ mut R
impl<W: Write + ?Sized, '_> Write for &'_ mut W
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
© 2010 The Rust Project Developers
Licensed under the Apache License, Version 2.0 or the MIT license, at your option.
https://doc.rust-lang.org/std/process/struct.Stdio.html