Capture both stdout & stderr via pipe
问题 I want to read both stderr and stdout from a child process, but it doesn't work. main.rs use std::process::{Command, Stdio}; use std::io::{BufRead, BufReader}; fn main() { let mut child = Command::new("./1.sh") .stdout(Stdio::piped()) .stderr(Stdio::piped()) .spawn() .unwrap(); let out = BufReader::new(child.stdout.take().unwrap()); let err = BufReader::new(child.stderr.take().unwrap()); out.lines().for_each(|line| println!("out: {}", line.unwrap()) ); err.lines().for_each(|line| println!(