This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Command line processing in does not match Microsoft parsing rules

On 2019-08-30 13:16, Stephen Provine via cygwin wrote:
> The standard rules for Microsoft command line processing are documented here:
> The Cygwin code for command line processing is in, function build_argv.
> The behaviors do not match. For instance, given a script like this:
>     #!/bin/bash
>     echo $1
> And the following invocation of bash.exe from a Windows command prompt:
>     bash.exe foo\"bar
> The result is:
>     foo\bar
> When the expected result is:
>     foo"bar
> As a workaround, you can achieve the expected result using:
>     bash.exe "foo\"bar"
> Which is great until you use a language like Go to shell exec the command line, and don't have control over how the command line string is generated from an original set of arguments. See:
> Go just reverses the Microsoft standard rules in the most efficient manner possible, but those command lines don't parse correctly in Cygwin processes.
> Go implements a pretty definitive command line parsing algorithm as a replacement for the CommandLineToArgv function in shell32.dll:
> The behavior here is based on a detailed analysis of what command line parsing "should" be in Windows:
> It would be very nice if Cygwin followed the same procedure at startup.

Cygwin command line parsing has to match Unix shell command line processing,
like argument splitting, joining within single or double quotes or after a
backslash escaped white space characters, globbing, and other actions normally
performed by a shell, when any Cygwin program is invoked from any Windows
program e.g. cmd, without those Windows limitations which exclude any use of a
backslash escape character except preceding another or a double quote.

Mixing Cygwin and Windows programs is a user choice requiring them to deal with
any interface issues: just use mintty with bash. ;^> It's actually the same
situation as invoking any another Cygwin program which also does some argument
interpretation, from the shell, possibly requiring nested quoting and escaping.

Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada

This email may be disturbing to some readers as it contains
too much technical detail. Reader discretion is advised.

Problem reports:
Unsubscribe info:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]