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

Quoted program names are not handled properly for CMD #613

Closed
m-haug opened this issue Jun 21, 2023 · 4 comments · Fixed by #616
Closed

Quoted program names are not handled properly for CMD #613

m-haug opened this issue Jun 21, 2023 · 4 comments · Fixed by #616
Labels
bug Something's not right!

Comments

@m-haug
Copy link

m-haug commented Jun 21, 2023

watchexec 1.22.3 does not handle cmd quoting properly on Windows.

This came up when investigating tectonic-typesetting/tectonic#1003. See there for the actual command that caused the issue. However, the issue also reproduces with the watchexec binary:

$ watchexec --version
watchexec 1.22.3 (eb19f83 2023-05-14)                                                                                                         commit-hash: eb19f837612a046d58173efae7e3b0825d475313
commit-date: 2023-05-14
build-date: 2023-05-14
release: 1.22.3
features:
$ watchexec -vvv --log-file --shell cmd -- '"C:\Users\Markus Haug\scoop\apps\tectonic\current\tectonic.exe"' -X build --open
Der Befehl "\"C:\Users\Markus Haug\scoop\apps\tectonic\current\tectonic.exe\"" ist entweder falsch geschrieben oder                           konnte nicht gefunden werden.
[[Command exited with 1]]

I've attached the log file of that run.

After some digging, I found the Command::raw_arg method. The documentation suggests that this a known issue when passing arguments via cmd.exe /C. On Windows, this match arm should probably be handled specially. Unfortunately, tokio does not seem to have the raw_arg method on its Command, so this would probably require a conversion from std's Command.

If you like, I can open a PR for this.

@m-haug m-haug added the bug Something's not right! label Jun 21, 2023
@m-haug
Copy link
Author

m-haug commented Jun 21, 2023

I've opened tokio-rs/tokio#5810 to hopefully get raw_arg on tokio's Command.

@passcod
Copy link
Member

passcod commented Jun 21, 2023

As a workaround, I think use --shell none and handling args manually would work?

@m-haug
Copy link
Author

m-haug commented Jun 21, 2023

In general/when using watchexec as a binary, that would work, I believe. But for the tectonic use case (watchexec), that workaround would require preprocessing the arguments using something like shlex, which may be too much effort for a temporary workaround.

@passcod
Copy link
Member

passcod commented Jun 22, 2023

Yeah, fair enough. If there's a workaround that can be done in the library code until the tokio support lands I'd be happy to merge it.

korrat added a commit to korrat/watchexec that referenced this issue Jun 23, 2023
CMD uses special handling for arguments to passed to /C. Unfortunately,
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 /C argument using the special
std::os::windows::process::CommandExt::raw_arg method. The StdCommand is
then converted to a TokioCommand and returned.

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

Fixes watchexec#613
korrat added a commit to korrat/watchexec that referenced this issue 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 watchexec#613
korrat added a commit to korrat/watchexec that referenced this issue 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 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something's not right!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants