Windows: only shell out to cmd for specific commands (#6253)

This commit is contained in:
Reilly Wood 2022-08-06 13:03:06 -07:00 committed by GitHub
parent 1ba5b25b29
commit a96fc21f88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -125,10 +125,24 @@ impl ExternalCommand {
#[cfg(windows)] #[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() { match fg_process.spawn() {
Err(_) => { Err(_) => {
let mut fg_process = 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(); child = fg_process.spawn();
} }
Ok(process) => { Ok(process) => {