Switch to using subprocess::shell (#1264)

* Switch to using `shell`

Switch to using the shell for subprocess to enable more natural shelling out.

* Update external.rs

* This is a test with .shell() for external

* El pollo loco's PR

* co co co

* Attempt to fix windows

* Fmt

* Less is more?

Co-authored-by: Andrés N. Robalino <andres@androbtech.com>
This commit is contained in:
Jonathan Turner
2020-01-24 05:21:05 +13:00
committed by GitHub
parent bc5a969562
commit 2b37ae3e81
4 changed files with 83 additions and 19 deletions

View File

@ -14,6 +14,16 @@ pub fn pipeline(commands: &str) -> String {
.to_string()
}
pub fn shell_os_paths() -> Vec<std::path::PathBuf> {
let mut original_paths = vec![];
if let Some(paths) = std::env::var_os("PATH") {
original_paths = std::env::split_paths(&paths).collect::<Vec<_>>();
}
original_paths
}
#[cfg(test)]
mod tests {
use super::pipeline;

View File

@ -28,18 +28,25 @@ macro_rules! nu {
$crate::fs::DisplayPath::display_path(&$path)
);
let dummies = $crate::fs::binaries();
let dummies = dunce::canonicalize(&dummies).unwrap_or_else(|e| {
let test_bins = $crate::fs::binaries();
let test_bins = dunce::canonicalize(&test_bins).unwrap_or_else(|e| {
panic!(
"Couldn't canonicalize dummy binaries path {}: {:?}",
dummies.display(),
test_bins.display(),
e
)
});
let mut paths = $crate::shell_os_paths();
paths.push(test_bins);
let paths_joined = match std::env::join_paths(paths.iter()) {
Ok(all) => all,
Err(_) => panic!("Couldn't join paths for PATH var."),
};
let mut process = match Command::new($crate::fs::executable_path())
// .env_clear()
.env("PATH", dummies)
.env("PATH", paths_joined)
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.spawn()
@ -103,18 +110,25 @@ macro_rules! nu_error {
$crate::fs::DisplayPath::display_path(&$path)
);
let dummies = $crate::fs::binaries();
let dummies = dunce::canonicalize(&dummies).unwrap_or_else(|e| {
let test_bins = $crate::fs::binaries();
let test_bins = dunce::canonicalize(&test_bins).unwrap_or_else(|e| {
panic!(
"Couldn't canonicalize dummy binaries path {}: {:?}",
dummies.display(),
test_bins.display(),
e
)
});
let mut paths = $crate::shell_os_paths();
paths.push(test_bins);
let paths_joined = match std::env::join_paths(paths.iter()) {
Ok(all) => all,
Err(_) => panic!("Couldn't join paths for PATH var."),
};
let mut process = Command::new($crate::fs::executable_path())
// .env_clear()
.env("PATH", dummies)
.env("PATH", paths_joined)
.stdout(Stdio::piped())
.stdin(Stdio::piped())
.stderr(Stdio::piped())