public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Command line processing in dcrt0.cc does not match Microsoft parsing rules
@ 2019-08-30 19:31 Stephen Provine via cygwin
  2019-08-30 20:53 ` Brian Inglis
  2019-08-30 21:21 ` Stephen Provine via cygwin
  0 siblings, 2 replies; 25+ messages in thread
From: Stephen Provine via cygwin @ 2019-08-30 19:31 UTC (permalink / raw)
  To: cygwin

The standard rules for Microsoft command line processing are documented here:

    https://docs.microsoft.com/en-us/previous-versions/17w5ykft(v=vs.85)

The Cygwin code for command line processing is in dcrt0.cc, function build_argv.

The behaviors do not match. For instance, given a test.sh script like this:

    #!/bin/bash
    echo $1

And the following invocation of bash.exe from a Windows command prompt:

    bash.exe test.sh 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 test.sh "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:

    https://github.com/golang/go/blob/master/src/syscall/exec_windows.go#L86

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:

    https://github.com/golang/go/commit/39c8d2b7faed06b0e91a1ad7906231f53aab45d1

The behavior here is based on a detailed analysis of what command line parsing "should" be in Windows:

    http://daviddeley.com/autohotkey/parameters/parameters.htm#WINARGV

It would be very nice if Cygwin followed the same procedure at startup.

Thanks,
Stephen


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2019-09-09 19:44 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-30 19:31 Command line processing in dcrt0.cc does not match Microsoft parsing rules Stephen Provine via cygwin
2019-08-30 20:53 ` Brian Inglis
2019-08-30 21:21 ` Stephen Provine via cygwin
2019-08-31  4:18   ` Brian Inglis
2019-09-03 16:38   ` Stephen Provine via cygwin
2019-09-04 16:20     ` Brian Inglis
2019-09-04 23:46     ` Stephen Provine via cygwin
2019-09-05  5:29       ` Brian Inglis
2019-09-05 18:31       ` Stephen Provine via cygwin
2019-09-05 19:05         ` Eric Blake
2019-09-05 22:01         ` Stephen Provine via cygwin
2019-09-05 22:46           ` Eric Blake
2019-09-05 23:45           ` Stephen Provine via cygwin
2019-09-06  0:46             ` Steven Penny
2019-09-06  1:26             ` Eric Blake
2019-09-06  6:20             ` Stephen Provine via cygwin
2019-09-07 21:50           ` Brian Inglis
2019-09-07 12:05         ` Andrey Repin
2019-09-07 12:20           ` Andrey Repin
2019-09-09 16:47           ` Stephen Provine via cygwin
2019-09-09 16:57             ` Stephen Provine via cygwin
2019-09-09 17:11               ` Eric Blake
2019-09-09 19:05                 ` Duncan Roe
2019-09-09 19:44                   ` Andrey Repin
2019-09-10 12:43                   ` Brian Inglis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).