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:date:from:reply-to:message-id:to:subject :in-reply-to:references:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=Jkou3s3VyaqhJ6nc 6SPL6Fhm/FhHffv3c4jPC6qKunGASNFJWSU2pY6d+GVFyoBwAMOrGKbPTICUGuVq hieEv/SLTWE3xbtyaPhZjH5L73nO9sXLmubzNi3lbLCRY5CaC4M90lhwSLWjiPBj VHt3KLsOeIZIAOxyhAyBMS7vCOk= 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:date:from:reply-to:message-id:to:subject :in-reply-to:references:mime-version:content-type :content-transfer-encoding; s=default; bh=yGD7Ygr9pVXfcz3pqc+YfY sbyho=; b=tiYrl2MfvaaGodsNvle2SD77dS1oZQrPhTgaKDwL87Czj6+G5EbNw7 +FhkpjjPIir/Jsknj5h6p5XurWEkmrU0WBlec115I5U5xEGB9VC3nWiWoB4nLps5 c9h72ehiqTVkUBVMhC1nQfBZOKUZXaF0xbmPFEoR3PJmphP7TaAAA= 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=-0.7 required=5.0 tests=BAYES_00,FREEMAIL_FROM,KAM_THEBAT,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=no version=3.3.1 spammy=H*M:yandex, H*UA:Bat!, H*F:D*ru X-HELO: forward106o.mail.yandex.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1567244102; bh=p7JxxrwvztqgyJaoB73Pq9PCIRV6QjvsAM1ndz8Dcjk=; h=In-Reply-To:Subject:To:Reply-To:From:Message-ID:References:Date; b=bHN7dFgTrLlHlxmAUlwwDpnhyg0g2b4ihfYV8fcGq6xCoMTMyoUFSdSi4Q+pfxxt5 NjvxTc64J7NFbPiZiBhPMJiVErouWx+I3ODQqtoTGgdoflYQyTi7X+AqtKuToR5eiR CnaaYvGHkUBjuPeX4xJ1HaxqMLwp3bXpZPuywaz0= Authentication-Results: mxback3o.mail.yandex.net; dkim=pass header.i=@yandex.ru Date: Sat, 31 Aug 2019 12:23:29 +0300 From: Andrey Repin Reply-To: cygwin AT cygwin DOT com Message-ID: <127324731.20190831122329@yandex.ru> To: Stephen Provine , cygwin AT cygwin DOT com Subject: Re: Command line processing in dcrt0.cc does not match Microsoft parsing rules In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Greetings, Stephen Provine! > 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 I would actually expect parsing error, but I guess, CMD gives you some slack. Then, the expected result is either 'foo\"bar' or 'foo\bar', since in CMD, the escape character is a caret (^). > 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 -- With best regards, Andrey Repin Saturday, August 31, 2019 11:27:38 Sorry for my terrible english... -- 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