From a96fc21f88507464a450767a62acaba03aa6b8e8 Mon Sep 17 00:00:00 2001 From: Reilly Wood <26268125+rgwood@users.noreply.github.com> Date: Sat, 6 Aug 2022 13:03:06 -0700 Subject: [PATCH] Windows: only shell out to cmd for specific commands (#6253) --- crates/nu-command/src/system/run_external.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/crates/nu-command/src/system/run_external.rs b/crates/nu-command/src/system/run_external.rs index 78c396912b..5c08898989 100644 --- a/crates/nu-command/src/system/run_external.rs +++ b/crates/nu-command/src/system/run_external.rs @@ -125,10 +125,24 @@ impl ExternalCommand { #[cfg(windows)] { + // Some common Windows commands are actually built in to cmd.exe, not executables in their own right. + // To support those commands, we "shell out" to cmd.exe. + + // This has the full list of cmd.exe "internal" commands: https://ss64.com/nt/syntax-internal.html + // I (Reilly) went through the full list and whittled it down to ones that are potentially useful: + const CMD_INTERNAL_COMMANDS: [&str; 8] = [ + "ASSOC", "DIR", "ECHO", "FTYPE", "MKLINK", "START", "VER", "VOL", + ]; + + let command_name_upper = self.name.item.to_uppercase(); + let use_cmd = CMD_INTERNAL_COMMANDS + .iter() + .any(|&cmd| command_name_upper == cmd); + match fg_process.spawn() { Err(_) => { let mut fg_process = - ForegroundProcess::new(self.create_process(&input, true, head)?); + ForegroundProcess::new(self.create_process(&input, use_cmd, head)?); child = fg_process.spawn(); } Ok(process) => {