X-Recipient: archive-cygwin AT delorie DOT com DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:reply-to:subject:to:references:from:message-id :date:mime-version:in-reply-to:content-type :content-transfer-encoding; q=dns; s=default; b=uHYy6EjmnIhvpjXz DS8r9MGAkaad1pvmSmN9eLUI+Xh5S4zpghlnU8s5kNj6s+kQA301KFmRxIfa6DMf 8QvwKz79znY07Ou2zBJvjDniIhTMGUoehf6JaYnwjH4R/XKsaldJFEXKg3BRbXN+ wUpnf0vIdoYFsVNUnRiokWVYiVQ= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:reply-to:subject:to:references:from:message-id :date:mime-version:in-reply-to:content-type :content-transfer-encoding; s=default; bh=P1pfdfe0+HNrIL77iZ4aX/ J0prE=; b=qdhHA3TgsLTnnTjN0qtsf9ynCWzL4q40jKs7RQk7kZH1lM3IiE3j9+ cLKrPlPctl/hop5CfRdp10PgOsq+7jfM2zLpCoTk8pZkHYkYIf7OEnRGnMczVS4t l7jGuA4fnhtcITJdzAHJczObc+0h9JBC8EkCj2Tfb6udVxJndx+zc= Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com 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 Reply-To: Brian DOT Inglis AT SystematicSw DOT ab DOT ca Subject: Re: Command line processing in dcrt0.cc does not match Microsoft parsing rules To: cygwin AT cygwin DOT com References: From: Brian Inglis Openpgp: preference=signencrypt Message-ID: <4e4e74fe-31b9-9e41-1d09-2a109e27b0b6@SystematicSw.ab.ca> Date: Fri, 30 Aug 2019 14:21:19 -0600 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 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