Use raw_arg for CMD on Windows (#616)

This commit is contained in:
korrat 2023-06-24 16:10:00 +02:00 committed by GitHub
parent 2a3a3dee5f
commit d72fc38e62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 6 deletions

View File

@ -99,9 +99,21 @@ impl Command {
args,
command,
} => {
if command.is_empty() {
return Err(RuntimeError::CommandShellEmptyCommand);
}
let (shcmd, shcliopt) = match shell {
#[cfg(windows)]
Shell::Cmd => ("cmd.exe", "/C"),
Shell::Cmd => {
use std::os::windows::process::CommandExt as _;
use std::process::Command as StdCommand;
// TODO this is a workaround until TokioCommand has a raw_arg method. See tokio-rs/tokio#5810.
let mut std_command = StdCommand::new("cmd.exe");
std_command.args(args).arg("/C").raw_arg(command);
return Ok(TokioCommand::from(std_command));
}
#[cfg(windows)]
Shell::Powershell => ("powershell.exe", "-Command"),
@ -117,10 +129,6 @@ impl Command {
}
};
if command.is_empty() {
return Err(RuntimeError::CommandShellEmptyCommand);
}
let mut c = TokioCommand::new(shcmd);
c.args(args);
c.arg(shcliopt).arg(command);

View File

@ -85,7 +85,7 @@ async fn windows_shell_cmd() -> Result<(), std::io::Error> {
assert!(Command::Shell {
shell: Shell::Cmd,
args: Vec::new(),
command: "echo hi".into()
command: r#""echo" hi"#.into()
}
.to_spawnable()
.unwrap()