Skip to content

Instantly share code, notes, and snippets.

Created January 24, 2020 16:01
What would you like to do?
Code shared from the Rust Playground
use std::process::{Command, Stdio};
fn main() {
let mut rev = Command::new("rev")
.expect("rev failed to spawn");
let mut stdin: Stdio = rev.stdin.take().expect("rev had no stdin?").into();
while Command::new("true")
.map(|status| status.success())
let mut fortune = Command::new("fortune")
.expect("fortune failed to spawn");
if !fortune
.expect("waiting for fortune to finish failed")
panic!("fortune failed??");
// **************** But this next part will always fail, can't get the pipe back
// **************** have to use a third party library to call the `dup` / `dup2` syscall
// **************** directly.
stdin = fortune
.expect("hey, fortune didn't give stdout back!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment