Skip to content
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

Use raw_arg for CMD on Windows #616

Merged
merged 1 commit into from
Jun 24, 2023

Conversation

korrat
Copy link
Contributor

@korrat korrat commented Jun 23, 2023

CMD uses special handling for arguments to passed to /C. Unfortunately, this causes errors with quoted program names in these arguments.

This commit implements a workaround: When CMD is requested, we build a std::process::Command and pass the the argument to /C using the special std::os::windows::process::CommandExt::raw_arg method. The StdCommand is then converted to a TokioCommand and returned.

Once tokio-rs/tokio#5810 is fixed, this workaround can be removed.

Fixes #613

CMD uses special handling for arguments to passed to /C. Unfortunately,
this causes errors with quoted program names in these arguments.

This commit implements a workaround: When CMD is requested, we build a
std::process::Command and pass the argument to /C using the special
std::os::windows::process::CommandExt::raw_arg method. The StdCommand is
then converted to a TokioCommand and returned.

Once tokio-rs/tokio#5810 is fixed, this workaround can be removed.

Fixes watchexec#613
@passcod
Copy link
Member

passcod commented Jun 24, 2023

Would this also be the case for other windows shells e.g. powershell?

@korrat
Copy link
Contributor Author

korrat commented Jun 24, 2023

The documentation for CommandExt::raw_arg refer specially to cmd.exe /C, so I'm assuming that the issue is isolated to CMD.

I've also done some testing with PowerShell on Windows. In my tests, unmodified watchexec correctly called the command I specified despite the quoted name (NB: PowerShell treats quoted arguments as strings, so you have to use special syntax & "command name").

@korrat
Copy link
Contributor Author

korrat commented Jun 24, 2023

Are the two test failures expected, or did I break something?

@passcod passcod enabled auto-merge (squash) June 24, 2023 14:05
@passcod passcod merged commit d72fc38 into watchexec:main Jun 24, 2023
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Quoted program names are not handled properly for CMD
2 participants