Use raw_arg for CMD on Windows (#616)
This commit is contained in:
parent
2a3a3dee5f
commit
d72fc38e62
|
@ -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);
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue