Several methods on Command, such as spawn or output, can be used
to spawn a process. In particular, output spawns the child process and
waits until the process terminates, while spawn will return a Child
that represents the spawned child process.

The stdout, stdin, and stderr of a child process can be
configured by passing an Stdio to the corresponding method on
Command. Once spawned, they can be accessed from the Child. For
example, piping output from one command into another command can be done
like so:

usestd::process::{Command, Stdio};
// stdout must be configured with `Stdio::piped` in order to use// `echo_child.stdout`letecho_child=Command::new("echo")
.arg("Oh no, a tpyo!")
.stdout(Stdio::piped())
.spawn()
.expect("Failed to start echo process");
// Note that `echo_child` is moved here, but we won't be needing// `echo_child` anymoreletecho_out=echo_child.stdout.expect("Failed to open echo stdout");
letmutsed_child=Command::new("sed")
.arg("s/tpyo/typo/")
.stdin(Stdio::from(echo_out))
.stdout(Stdio::piped())
.spawn()
.expect("Failed to start sed process");
letoutput=sed_child.wait_with_output().expect("Failed to wait on sed");
assert_eq!(b"Oh no, a typo!\n", output.stdout.as_slice());Run