Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions examples/std_misc/process/pipe/pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,23 @@ fn main() {
};

{
// Write a string to the stdin of `wc`
// Write a string to the `stdin` of `wc`.
//
// `stdin` has type `Option<ChildStdin>`, but since we know this instance
// must have one, we can directly `unwrap` it.
match process.stdin.unwrap().write_all(PANGRAM.as_bytes()) {
Err(why) => panic!("couldn't write to wc stdin: {}",
Error::description(&why)),
Ok(_) => println!("sent pangram to wc"),
}

// `stdin` gets `drop`ed here, and the pipe is closed
// `stdin` gets `drop`ed here, and the pipe is closed.
//
// This is very important, otherwise `wc` wouldn't start processing the
// input we just sent
// input we just sent.
}

// The `stdout` field also has type `Option<PipeStream>`
// the `as_mut` method will return a mutable reference to the value
// wrapped in a `Some` variant
// The `stdout` field also has type `Option<ChildStdout>` so must be unwrapped.
let mut s = String::new();
match process.stdout.unwrap().read_to_string(&mut s) {
Err(why) => panic!("couldn't read wc stdout: {}",
Expand Down