From bf9340ec4801353742d0d67a178cf75304e3db4a Mon Sep 17 00:00:00 2001 From: JT <547158+jntrnr@users.noreply.github.com> Date: Sat, 22 Jan 2022 18:35:52 -0500 Subject: [PATCH] Only escape backslash on windows (#825) --- crates/nu-command/src/system/run_external.rs | 30 +++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/crates/nu-command/src/system/run_external.rs b/crates/nu-command/src/system/run_external.rs index 6103af4a..32deeff2 100644 --- a/crates/nu-command/src/system/run_external.rs +++ b/crates/nu-command/src/system/run_external.rs @@ -277,9 +277,21 @@ impl<'call> ExternalCommand<'call> { head }; - let head = head.replace("\\", "\\\\"); + //let head = head.replace("\\", "\\\\"); - let mut process = std::process::Command::new(&head); + let new_head; + + #[cfg(windows)] + { + new_head = head.replace("\\", "\\\\"); + } + + #[cfg(not(windows))] + { + new_head = head; + } + + let mut process = std::process::Command::new(&new_head); for arg in &self.args { let arg = trim_enclosing_quotes(arg); @@ -291,9 +303,19 @@ impl<'call> ExternalCommand<'call> { arg }; - let arg = arg.replace("\\", "\\\\"); + let new_arg; - process.arg(&arg); + #[cfg(windows)] + { + new_arg = arg.replace("\\", "\\\\"); + } + + #[cfg(not(windows))] + { + new_arg = arg; + } + + process.arg(&new_arg); } process