Rust-Programming-Cookbook/Chapter05/sample_child_process.rs

30 wiersze
780 B
Rust
Czysty Zwykły widok Historia

2017-07-31 06:59:18 +00:00
//-- #########################
//-- Task: To call a child process
//-- Author: Vigneshwer.D
//-- Version: 1.0.0
//-- Date: 19 March 17
//-- #########################
// Call the standard library
use std::process::Command;
// Main execution of the code
fn main() {
// Command to be executed
let output = Command::new("rustc")
.arg("--version")
.output().unwrap_or_else(|e| {
panic!("failed to execute process: {}", e)
});
// printing the output values
if output.status.success() {
let s = String::from_utf8_lossy(&output.stdout);
print!("rustc succeeded and stdout was:\n{}", s);
} else {
let s = String::from_utf8_lossy(&output.stderr);
print!("rustc failed and stderr was:\n{}", s);
}
}