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 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");
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}; let output = Command::new("rev") .stdin(Stdio::inherit()) .stdout(Stdio::piped()) .output() .expect("Failed to execute command"); println!("You piped in the reverse of: {}", String::from_utf8_lossy(&output.stdout));
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
fn fmt(&self, f: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl From<ChildStdin> for Stdio
fn from(child: ChildStdin) -> Stdio
[src]
Performs the conversion.
impl From<ChildStdout> for Stdio
fn from(child: ChildStdout) -> Stdio
[src]
Performs the conversion.
impl From<ChildStderr> for Stdio
fn from(child: ChildStderr) -> Stdio
[src]
Performs the conversion.
impl From<File> for Stdio
fn from(file: File) -> Stdio
[src]
Performs the conversion.
impl FromRawFd for Stdio
unsafe fn from_raw_fd(fd: RawFd) -> Stdio
[src]
Constructs a new instance of Self
from the given raw file descriptor. Read more
impl FromRawHandle for Stdio
unsafe fn from_raw_handle(handle: RawHandle) -> Stdio
[src]
Constructs a new I/O object from the specified raw handle. Read more
© 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