How to get status code of a program which was used as a pipe source without violating Rust's borrow rule?
⚓ Rust 📅 2025-06-20 👤 surdeus 👁️ 15I'm trying to pipe a program onto another, but I can't call source.wait() due to source.stdout being already moved.
use std::process::{Command, Stdio};
fn main() {
let mut source = Command::new("echo").arg("hello").spawn().unwrap();
Command::new("cowsay")
.stdin(source.stdout.unwrap())
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.spawn()
.unwrap()
.wait()
.unwrap();
let source_status = source.wait().unwrap(); // error here
}
1 post - 1 participant
🏷️ rust_feed