Child processes

The process::Output struct represents the output of a finished child process,
and the process::Command struct is a process builder.

  1. use std::process::Command;
  2. fn main() {
  3. let output = Command::new("rustc")
  4. .arg("--version")
  5. .output().unwrap_or_else(|e| {
  6. panic!("failed to execute process: {}", e)
  7. });
  8. if output.status.success() {
  9. let s = String::from_utf8_lossy(&output.stdout);
  10. print!("rustc succeeded and stdout was:\n{}", s);
  11. } else {
  12. let s = String::from_utf8_lossy(&output.stderr);
  13. print!("rustc failed and stderr was:\n{}", s);
  14. }
  15. }

(You are encouraged to try the previous example with an incorrect flag passed
to rustc)