mirror of
https://github.com/watchexec/watchexec.git
synced 2024-09-29 14:41:35 +02:00
Use raw_arg for CMD on Windows (#616)
This commit is contained in:
parent
2a3a3dee5f
commit
d72fc38e62
@ -99,9 +99,21 @@ impl Command {
|
|||||||
args,
|
args,
|
||||||
command,
|
command,
|
||||||
} => {
|
} => {
|
||||||
|
if command.is_empty() {
|
||||||
|
return Err(RuntimeError::CommandShellEmptyCommand);
|
||||||
|
}
|
||||||
|
|
||||||
let (shcmd, shcliopt) = match shell {
|
let (shcmd, shcliopt) = match shell {
|
||||||
#[cfg(windows)]
|
#[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)]
|
#[cfg(windows)]
|
||||||
Shell::Powershell => ("powershell.exe", "-Command"),
|
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);
|
let mut c = TokioCommand::new(shcmd);
|
||||||
c.args(args);
|
c.args(args);
|
||||||
c.arg(shcliopt).arg(command);
|
c.arg(shcliopt).arg(command);
|
||||||
|
@ -85,7 +85,7 @@ async fn windows_shell_cmd() -> Result<(), std::io::Error> {
|
|||||||
assert!(Command::Shell {
|
assert!(Command::Shell {
|
||||||
shell: Shell::Cmd,
|
shell: Shell::Cmd,
|
||||||
args: Vec::new(),
|
args: Vec::new(),
|
||||||
command: "echo hi".into()
|
command: r#""echo" hi"#.into()
|
||||||
}
|
}
|
||||||
.to_spawnable()
|
.to_spawnable()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
Loading…
Reference in New Issue
Block a user