delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2016/05/06/04:03:49

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:from:to:references:in-reply-to:subject:date
:message-id:mime-version:content-type:content-transfer-encoding;
q=dns; s=default; b=eUI0UhWqSVqZLL2OMLppoNQ0egoSfPwD2UAl1seuDIZ
8rBVkRrawfgKL5R1Re4risi3NPRIgcClsBGHZzuD+ktGIpof88MjhNZaMNqYNyLy
BmIMdn+WQsa9U6hGee57vNJEWpf+l89idteTzIXdzjFl/q5dRdeG3pQXnADq+kbA
=
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:from:to:references:in-reply-to:subject:date
:message-id:mime-version:content-type:content-transfer-encoding;
s=default; bh=Cr96mR1nSc/+NK8751NcMu4LGJk=; b=Woq4IGT0kUtv2EsEa
8ldH0rjnXNTMcWm+KjvNVdRGlm4AlYibhPk9iLEWqG0ZGbQPfb1nA2Nyv1gUVfvR
LTpxTajA6JjZl+VkeNuolZ5wXr/j/0t6qaygodT2Pq24oGr0wlNZXq2/GesnUVLF
4DreQX1MZJLWNisXZ+snamEDEw=
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
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-Virus-Found: No
X-Spam-SWARE-Status: No, score=2.1 required=5.0 tests=BAYES_50,LIKELY_SPAM_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=no version=3.3.2 spammy=H*UA:16.0, dcrt0cc, createprocess, api's
X-HELO: outmail149080.authsmtp.com
From: "David Allsopp" <dra-news AT metastack DOT com>
To: <cygwin AT cygwin DOT com>
References: <005c01d1a6e2$30270ba0$907522e0$@metastack.com> <CACoZoo1LObZ0zu9X5O6dV4cO4jN+GO28bdRbuDkTMdaKHXpVbQ AT mail DOT gmail DOT com>
In-Reply-To: <CACoZoo1LObZ0zu9X5O6dV4cO4jN+GO28bdRbuDkTMdaKHXpVbQ@mail.gmail.com>
Subject: RE: Formatting command line arguments when starting a Cygwin process from a native process
Date: Fri, 6 May 2016 10:03:22 +0200
Message-ID: <000101d1a76d$c37c6b80$4a754280$@metastack.com>
MIME-Version: 1.0
X-Server-Quench: 024ce601-1361-11e6-829e-00151795d556
X-AuthReport-Spam: If SPAM / abuse - report it at: http://www.authsmtp.com/abuse
X-AuthRoute: OCd1ZAARAlZZVg1f DC4bFwdFRBksPQFF ChxFJgxfNlEYWhtQ NG5RP1VMMVtaTlZc TWYNRCkFGUJzWWJz ewpYZwVeaEhLEQdr U1ZIQldMFgRqHx0A AgEcVwZzOUBCfnZz GjU6XnFeWU14O0V7 Q0oaFW8CNjJmaGEC UUNedh5VcVZMYxdH YwViVHMMZGQAb380 QlJtKQocb31xLz5Q Sx0RLFQdCU0MGzs1 QRxKGTQpEAUMXSou KhEgNkVUA0YcNA0p LVI7RVMePFcbQiZP EF5MBmdBPV4KSjEw RQ1AWktWGXVbSDtd HBBgOgVPCTFJQUIA
X-Authentic-SMTP: 61633634383431.1037:706
X-AuthFastPath: 0 (Was 255)
X-AuthSMTP-Origin: 213.105.212.114/25
X-AuthVirus-Status: No virus detected - but ensure you scan with your own anti-virus system.
X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id u4683i1E006215

[With apologies if threading is broken; I erroneously thought as the list was not subscriber-only that replies would use reply-all and so wasn't subscribed]

On Thu, May 5, 2016 at 06:47 PM, Erik Soderquist wrote:
> On Thu, May 5, 2016 at 11:24 AM, David Allsopp wrote:
> >
> > I am trying to work out the precise details for character escaping
> > when starting a Cygwin process from a native (i.e. non-Cygwin) Windows
> process.
> <snip>
> > For example:
> >
> >   argv[0] = "foo"
> >   argv[1] = "bar baz"
> >
> > then the resulting command line string should be:
> >
> >   lpCommandLine = "foo bar\" \"baz"
> 
> If I recall correctly, Windows cmd.exe uses the carrot (^) as the general
> escape from shell character, so
> 
> C:\cygwin64\bin>.\echo.exe -e ^"hello\nworld^"	
> hello
> world
> 
> works.

Indeed - but I'm not using cmd, or any shell for that matter (that's actually the point) - I am in a native Win32 process invoking a Cygwin process directly using the Windows API's CreateProcess call. As it happens, the program I have already has the arguments for the Cygwin process in an array, but Windows internally requires a single command line string (which is not in any related to Cmd).

> However, I've found Windows's interpretation to be inconsistent, so often
> have to play with it to find what the "right combination" is for a
> particular instance.
> 
> I find echoing the parameters to a temporary text file and then using the
> file as input to be more reliable and easier to troubleshoot, and it
> breaks apart whether it is Windows cli inconsistencies or receiving
> program issues very nicely with the text file content as an intermediary

This is an OK tack, but I don't wish to do this by experimentation and get caught out later by a case I didn't think of, so what I'm trying to determine is *exactly* how the Cygwin DLL processes the command line via its source code so that I can present it with my argv array converted to a single command line and be certain that the Cygwin will recover the same argv DLL.

My reading of the relevant sources suggests that with globbing disabled, backslash escape sequences are *never* interpreted (since the quote function returns early - dcrt0.cc, line 171). If there is no way of encoding the double quote character, then perhaps I have to run with globbing enabled but ensure that the globify function will never actually expand anything - but as that's a lot of work, I was wondering if I was missing something with the simpler "noglob" case.


David


--
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


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019