From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 62173 invoked by alias); 30 Aug 2019 20:21:25 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 62166 invoked by uid 89); 30 Aug 2019 20:21:25 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy=H*M:1d09, escaping X-HELO: smtp-out-no.shaw.ca Received: from smtp-out-no.shaw.ca (HELO smtp-out-no.shaw.ca) (64.59.134.12) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 30 Aug 2019 20:21:22 +0000 Received: from [192.168.1.114] ([24.64.172.44]) by shaw.ca with ESMTP id 3nOZiIq2QUIS23nOai4Akm; Fri, 30 Aug 2019 14:21:21 -0600 Reply-To: Brian.Inglis@SystematicSw.ab.ca Subject: Re: Command line processing in dcrt0.cc does not match Microsoft parsing rules To: cygwin@cygwin.com References: From: Brian Inglis Openpgp: preference=signencrypt Message-ID: <4e4e74fe-31b9-9e41-1d09-2a109e27b0b6@SystematicSw.ab.ca> Date: Fri, 30 Aug 2019 20:53:00 -0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2019-08/txt/msg00433.txt.bz2 On 2019-08-30 13:16, Stephen Provine via cygwin wrote: > 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. 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: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple