-
Notifications
You must be signed in to change notification settings - Fork 13
fix(xtask): launch non-exe commands through cmd.exe on Windows #79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,9 +30,18 @@ pub fn spawn_child(label: &str, cmd: &str, args: &[&str], cwd: &Path) -> Option< | |
| console::style(label).cyan().bold(), | ||
| ); | ||
|
|
||
| let mut command = Command::new(cmd); | ||
| // On Windows, non-.exe commands (e.g. .cmd/.bat scripts like pnpm) must be | ||
| // launched through cmd.exe because CreateProcessW only resolves .exe files. | ||
| let mut command = if cfg!(windows) { | ||
| let mut c = Command::new("cmd"); | ||
| c.arg("/c").arg(cmd).args(args); | ||
| c | ||
| } else { | ||
| let mut c = Command::new(cmd); | ||
| c.args(args); | ||
| c | ||
| }; | ||
|
||
| command | ||
| .args(args) | ||
| .current_dir(cwd) | ||
| .stdin(Stdio::inherit()) | ||
| .stdout(Stdio::inherit()) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When
cmd.exe /cis used, individual arguments in theargsslice are passed as separatearg()calls, butcmd.exereassembles them into a single command line string using its own quoting rules. If any argument or thecmdvalue contains spaces, special characters (&,|,>,<,^,%,!), or quotes,cmd.exemay misinterpret them, leading to incorrect behavior or potential argument injection. The current callers only pass simple strings like"start:server", so this is not an immediate problem, but it is a latent hazard as the function is public and could be called with arbitrary arguments in the future. Consider documenting this limitation or usingstd::os::windows::process::CommandExt::raw_argto bypass cmd.exe's re-quoting.