Skip to content

Instantly share code, notes, and snippets.

@mr-pascal
Last active June 29, 2022 19:38
Show Gist options
  • Save mr-pascal/829e8ed0872606f5a4287fb27191489d to your computer and use it in GitHub Desktop.
Save mr-pascal/829e8ed0872606f5a4287fb27191489d to your computer and use it in GitHub Desktop.
use std::process::Command;
fn main() {
// spawn()
println!("Running via 'spawn()'");
let mut out = Command::new("ls")
.arg("-l")
.arg("-a")
.spawn()
.expect("ls command failed to start");
out.wait().expect("Failing while waiting");
println!("{:?}", out);
// output()
println!("");
println!("Running via 'output()'");
let out2 = Command::new("ls")
.arg("-l")
.arg("-a")
.output()
.expect("ls command failed to start");
println!("");
println!("{:?}", out2);
// status()
println!("");
println!("Running via 'status()'");
let out3 = Command::new("ls")
.arg("-l")
.arg("-a")
.status()
.expect("ls command failed to start");
println!("");
println!("{:?}", out3);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment