Re: Incorrect command line handling when launching Cygwin program from Windows

2025年8月02日 03:51:10 -0700

Greetings, Old, Oliver!
> Hello!
> I have recently noticed that the Windows command line parsing routine of 
> Cygwin programs does not
> work correctly when an escaped quotation mark is included. This is relevant 
> when launching a Cygwin-
> based GCC through Windows CMake-generated Ninja files. We are passing 
> preprocessor definitions
> containing quotation marks to GCC and CMake wants to pass them 
> backslash-escaped, but unquoted, on
> the command line.
> A test program I have written to inspect this issue:
> #include <stdio.h>
> int main(int argc, char** argv) {
> for (int i = 0; i < argc; ++i) puts(argv[i]);
> }
> Running it (via cmd.exe):
>>echo.exe a b\"c\" d
> echo
> a
> b\c" d
When you run a program using cmd.exe you are using CMD's parsing semantics.
(Or, rather, the cmd parses the string first and then sends the results to an
executed command.)
If you want to escape it (at least partially), use cmd's /S switch and wrap
your ENTIRE command in quotation marks.
> The first escape sequence is ignored, but the quote is read and causes the 
> parser to switch to
> quoted argument mode where it recognizes the remaining escaped quotes as it 
> already should have done
> in regular parsing mode. It then proceeds to eat the remaining command line 
> as there aren't any
> unescaped quotation marks, usually leading GCC to complain about no input 
> files being given.
> Running the Windows-native version of the program:
>>echo-win32.exe a b\"c\" d
> echo-win32.exe
> a
> b"c"
> d
> This should be the expected output. Is the way the escaped quotation mark is 
> treated intended
> behavior? I cannot really see how it would be, given that the parser is only 
> used for command lines
> stemming from being launched by Windows-native programs.
Wrong question.
-- 
With best regards,
Andrey Repin
Saturday, August 2, 2025 13:36:48
Sorry for my terrible english...
-- 
Problem reports: https://cygwin.com/problems.html
FAQ: https://cygwin.com/faq/
Documentation: https://cygwin.com/docs.html
Unsubscribe info: https://cygwin.com/ml/#unsubscribe-simple

Reply via email to