Dont let Nu childs become zombies.

This commit is contained in:
Andrés N. Robalino 2019-08-06 00:34:06 -05:00
parent c231dd32cd
commit b38d54e033

View file

@ -21,7 +21,7 @@ macro_rules! nu {
$cwd, $commands
);
let process = match Command::new(helpers::executable_path())
let mut process = match Command::new(helpers::executable_path())
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.spawn()
@ -30,22 +30,18 @@ macro_rules! nu {
Err(why) => panic!("Can't run test {}", why.description()),
};
match process.stdin.unwrap().write_all(commands.as_bytes()) {
Err(why) => panic!("couldn't write to wc stdin: {}", why.description()),
Ok(_) => {}
}
let stdin = process.stdin.as_mut().expect("couldn't open stdin");
stdin
.write_all(commands.as_bytes())
.expect("couldn't write to stdin");
let mut _s = String::new();
let output = process
.wait_with_output()
.expect("couldn't read from stdout");
match process.stdout.unwrap().read_to_string(&mut _s) {
Err(why) => panic!("couldn't read stdout: {}", why.description()),
Ok(_) => {
let _s = _s.replace("\r\n", "\n");
}
}
let _s = _s.replace("\r\n", "");
let $out = _s.replace("\n", "");
let $out = String::from_utf8_lossy(&output.stdout);
let $out = $out.replace("\r\n", "");
let $out = $out.replace("\n", "");
};
}
@ -189,6 +185,10 @@ pub fn file_exists_at(full_path: &str) -> bool {
PathBuf::from(full_path).exists()
}
pub fn dir_exists_at(full_path: &str) -> bool {
PathBuf::from(full_path).exists()
}
pub fn delete_directory_at(full_path: &str) {
std::fs::remove_dir_all(PathBuf::from(full_path)).expect("can not remove directory");
}