Skip to content

Instantly share code, notes, and snippets.

@MartinWallgren
Created May 19, 2019 14:26
Show Gist options
  • Save MartinWallgren/ec4709c7ed6b2eda2fc4bde0988fa99b to your computer and use it in GitHub Desktop.
Save MartinWallgren/ec4709c7ed6b2eda2fc4bde0988fa99b to your computer and use it in GitHub Desktop.
Halp!
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