1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
use std::process::Command; use std::io::ErrorKind; pub fn cmd<F>(program: &'static str, args: F) where F: FnOnce(&mut Command) { let mut cmd = Command::new(program); args(&mut cmd); println!("Running {:?}", cmd); let out = cmd.output().unwrap_or_else(|e| { if e.kind() == ErrorKind::NotFound { panic!("Failed to execute command: {}\nIs `{}` not installed?", e, program); } panic!("Failed to execute command: {}", e); }); let status = out.status; if !status.success() { let log = String::from_utf8(out.stdout).unwrap(); let err = String::from_utf8(out.stderr).unwrap(); panic!("Command did not executed successfully, got: {}\n-----stdout\n{}\n-----stderr\n{}", status, log, err); } }