Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upCommand does not escape arguments as expected on windows #29494
Comments
This comment has been minimized.
This comment has been minimized.
|
Edit: Nevermind, a look at the documentation reveals that this function takes a single string as command to be executed. |
This comment has been minimized.
This comment has been minimized.
|
At the very least it should strive to perform the exact, minimal inverse of CommandLineToArgvW (a very nontrivial task unfortunately, see: http://blogs.msdn.com/b/twistylittlepassagesallalike/archive/2011/04/23/everyone-quotes-arguments-the-wrong-way.aspx which describes the problems well enough, but the final solution given is actually still wrong!) This would be enough to fix the problems for me with msiexec and possibly cmd. However, there's no requirement that processes on windows use For reference, the string edit: Actually, no it seems it does still need escaping, it may just be that msiexec does not use CommandLineToArgvW. |
alexcrichton
added
the
O-windows
label
Nov 2, 2015
Diggsey
referenced this issue
Mar 9, 2016
Closed
MSI Error 1639: 'Invalid command line argument' during installation #89
brson
changed the title
Command does not handle arguments well on windows.
Command does not escape arguments as expected on windows
Apr 11, 2017
brson
added
P-low
T-libs
I-needs-decision
labels
Apr 11, 2017
This comment has been minimized.
This comment has been minimized.
|
This could probably be solved by adding a |
This comment has been minimized.
This comment has been minimized.
|
This popped up on Stack Overflow: let comm = r#""C:\Program Files\Google\Chrome\Application\chrome.exe" https://stackoverflow.com/"#;
let mut cmd = Command::new("cmd");
cmd.arg("/c");
cmd.arg(comm);As I understand it, it is expected to execute
But instead executes
Note that the inner |
This comment has been minimized.
This comment has been minimized.
mzji
commented
Jul 1, 2017
|
Met this issue too. Do we have any workaround now? |
This comment has been minimized.
This comment has been minimized.
|
The workaround is calling |
This comment has been minimized.
This comment has been minimized.
mzji
commented
Jul 2, 2017
|
@retep998 I changed the argument in the command line to avoid the quotes. |
retep998
referenced this issue
Jul 20, 2017
Closed
std::Command::new fails for some CMD scripts on Windows 10 msvc nightly 1.19/1.20 #42791
Mark-Simulacrum
added
the
C-bug
label
Jul 24, 2017
This comment has been minimized.
This comment has been minimized.
rivy
commented
Nov 18, 2018
•
|
I'm now running into this issue while trying to fix The summary at this point seems to be, at least for Windows, with its some-what crazy command-line quoting, that there are simply some command lines which are valid and used which cannot be generated by the current IMO, there needs to be some way of using An addition to the API of Any thoughts? And what should be done to push this issue forward? cc: @rivy |
Diggsey commentedOct 31, 2015
Currently the windows implementation of Command will automatically attempt to escape arguments before concatenating them into a single command line string to be passed to CreateProcess. However, the escaping method used doesn't work for many windows command-line tools, including
cmd,msiexecand others.As an example, it is impossible to specify arguments like this:
ARG="some parameter with spaces"because Command will try to quote the entire thing, whereas msiexec expects only the value to be quoted.
What's required is a way to pass arguments through unchanged: I suggest an
arg_raworarg_unescapedmethod be added to Command. This function can either be a windows-specific extension, or a no-op on other platforms. The advantage of the latter is that it avoids the need tocfgout code that relies on it at compile time.