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

@ -209,10 +209,26 @@ async fn run_with_stdin(
let process_args = args.iter().map(|arg| {
let arg = expand_tilde(arg.deref(), || home_dir.as_ref());
if let Some(unquoted) = remove_quotes(&arg) {
unquoted.to_string()
} else {
arg.as_ref().to_string()
#[cfg(not(windows))]
{
if argument_contains_whitespace(&arg) && argument_is_quoted(&arg) {
if let Some(unquoted) = remove_quotes(&arg) {
format!(r#""{}""#, unquoted)
} else {
arg.as_ref().to_string()
}
} else {
arg.as_ref().to_string()
}
}
#[cfg(windows)]
{
if let Some(unquoted) = remove_quotes(&arg) {
unquoted.to_string()
} else {
arg.as_ref().to_string()
}
}
}).collect::<Vec<String>>();
@ -248,11 +264,24 @@ async fn spawn(
let command = command.clone();
let name_tag = command.name_tag.clone();
let mut process = Exec::cmd(&command.name);
let mut process = {
#[cfg(windows)]
{
let mut process = Exec::cmd("cmd");
process = process.arg("/c");
process = process.arg(&command.name);
for arg in args {
process = process.arg(&arg);
}
process
}
for arg in args {
process = process.arg(&arg);
}
#[cfg(not(windows))]
{
let cmd_with_args = vec![command.name.clone(), args.join(" ")].join(" ");
Exec::shell(&cmd_with_args)
}
};
process = process.cwd(path);
trace!(target: "nu::run::external", "cwd = {:?}", &path);
@ -415,6 +444,17 @@ fn remove_quotes(argument: &str) -> Option<&str> {
Some(&argument[1..size - 1])
}
#[allow(unused)]
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::{