From 1420d8a92f20854ed77d2b43a0e7150bd1f0e5a9 Mon Sep 17 00:00:00 2001 From: Jun Wu Date: Thu, 6 Jul 2023 08:52:08 -0700 Subject: [PATCH] commandserver: fix ui.system on Windows Summary: The `cmd.exe` does not use the "common" argv[] parsing [1] [2]. For example, the Rust code: Command::new("cmd.exe").arg("/c").arg(r#"notepad "a b.txt"#) will execute (Windows OS command line, as a single string): cmd.exe /c "notepad \"a b.txt\"" which will execute: notepad \"a b.txt\" and notepad will complain that the file cannot be found. To fix it we need to pass the unquoted command and execute either: cmd.exe /c "notepad "a b.txt"" cmd.exe /c notepad "a b.txt" which will execute: notepad "a b.txt" See also https://github.com/rust-lang/rust/issues/29494. [1]: https://learn.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-commandlinetoargvw [2]: https://learn.microsoft.com/en-us/cpp/c-language/parsing-c-command-line-arguments Reviewed By: zzl0 Differential Revision: D47242639 fbshipit-source-id: c75aa83430520c29002a095333546cc48695244e --- eden/scm/lib/commandserver/src/ipc.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/eden/scm/lib/commandserver/src/ipc.rs b/eden/scm/lib/commandserver/src/ipc.rs index 59232d951a129..9ec34d98c3110 100644 --- a/eden/scm/lib/commandserver/src/ipc.rs +++ b/eden/scm/lib/commandserver/src/ipc.rs @@ -59,8 +59,15 @@ impl Client { } else { Command::new("/bin/sh") }; - cmd.arg(if cfg!(windows) { "/c" } else { "-c" }) - .arg(command); + #[cfg(windows)] + { + use std::os::windows::process::CommandExt; + cmd.arg("/c").raw_arg(command); + } + #[cfg(not(windows))] + { + cmd.arg("-c").arg(command); + } cmd } else { Command::new(command)