Skip to content

Commit

Permalink
commandserver: fix ui.system on Windows
Browse files Browse the repository at this point in the history
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 rust-lang/rust#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
  • Loading branch information
quark-zju authored and facebook-github-bot committed Jul 6, 2023
1 parent d8285f9 commit 1420d8a
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions eden/scm/lib/commandserver/src/ipc.rs
Expand Up @@ -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)
Expand Down

0 comments on commit 1420d8a

Please sign in to comment.