Created
May 19, 2019 14:26
-
-
Save MartinWallgren/ec4709c7ed6b2eda2fc4bde0988fa99b to your computer and use it in GitHub Desktop.
Halp!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn execute_hook(path: &Path, args: &Vec<String>, stdin: &Vec<u8>) { | |
let name = path.file_name().expect("Failed to get file name of hook."); | |
println!("Execute {:?}", &name); | |
let mut p = Command::new(path) | |
.stdin(Stdio::piped()) | |
.stdout(Stdio::inherit()) | |
.stderr(Stdio::inherit()) | |
.args(args) | |
.spawn() | |
.expect(&format!("Failed to execute {:?}", &name)); | |
p.stdin | |
.expect("Failed to open stdin for writing") | |
.write_all(stdin) | |
.expect("Failed write to stdin"); | |
let status = p.wait().expect(&format!("Failed to execute {:?}", &name)); | |
if !status.success() { | |
match status.code() { | |
Some(code) => panic!("{:#?} returned {}", name, code), | |
None => panic!("{:#?} terminated by signal", name), | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment