delorie.com/archives/browse.cgi | search |
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=Ztims0rEMzIX+djlIjF55PYTHNTfc7hvO9idd2Gm1e+ | |
kRh1iWovrhej83PzsR5MQ4QdfNEHGmTscOLwbqpowzSnspkwiRrw1eFa1+R+ZTeG | |
cTqb3f4tUj7uqPsDbOtiDYNIHpYi4QHbEuKF/hoT0NB3H73DBU8eAj8RS+LRrQ6c | |
= | |
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=irUNnfLJ7gIyBY5x81KQpX6sUt4=; b=yJHny8vEQoyDLgS2Y | |
MXLxFWGhPlOIkIGQkhBAXOLgPoYWuOutgSGNhVcyIrUjIpO4grC1hkClk1uWqVLQ | |
5mepSBu9OL8FQbttx5clTgS66sT/MyNNZADa6vpgviuUBpvZ6iafq9LDM3zdE/hS | |
FyZKQ3RnxxJe/Bel8sa6xyExEA= | |
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=0.9 required=5.0 tests=BAYES_50,RCVD_IN_DNSWL_LOW,SPF_NEUTRAL autolearn=ham version=3.3.2 spammy=CYGWIN, cygwins, UD:callee.c, callerc |
X-HELO: | outmail149055.authsmtp.co.uk |
From: | "David Allsopp" <dra27 AT cantab DOT net> |
To: | "'Aaron Digulla'" <digulla AT hepe DOT com>, <cygwin AT cygwin DOT com> |
References: | <E51C5B015DBD1348A1D85763337FB6D9F04BD207 AT Remus DOT metastack DOT local> <6533-5731e280-9-60079180 AT 7271027> |
In-Reply-To: | <6533-5731e280-9-60079180@7271027> |
Subject: | RE: Formatting command line arguments when starting a Cygwin process from a native process |
Date: | Tue, 10 May 2016 19:02:21 +0200 |
Message-ID: | <000001d1aadd$b8649970$292dcc50$@cantab.net> |
MIME-Version: | 1.0 |
X-Server-Quench: | f7115e98-16d0-11e6-829e-00151795d556 |
X-AuthReport-Spam: | If SPAM / abuse - report it at: http://www.authsmtp.com/abuse |
X-AuthRoute: | OCd1ZAARAlZZVg1A VQsPBSlcQA9jIBBQ FxoeKRdbOF4EFV4Q JB8CaX9aIRpGHQgH E2cDUVRWWl9yF2F0 aBRQbQBDYEtMQQRr VFdLR01TWkBscGQD e2VFUhtyfwdONn9x bUZiECZcXUV/IE91 X09SQW0bZGY1bn0X UkkNagNUcQZLeRZA PlV6Uj1vFG8XECUi GgYvIzE3Mn1ULyFQ SwcBZVYTR0tDFyQz WhUPGyk0VVIFSiN7 NAAvMEIdGklZOw0Z IFQ+WFRQewcIDQZT BFoFDjVeIhEIDywi EQJEUAYGCjpWTDxH agAA |
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-IsSubscribed: | yes |
X-MIME-Autoconverted: | from quoted-printable to 8bit by delorie.com id u4AH2oDH008123 |
Aaron Digulla wrote: > David Allsopp wrote: > > Aaron Digulla wrote: > > > > > > Am Samstag, 07. Mai 2016 09:45 CEST, "David Allsopp" > > > schrieb: > > > > > > > > > > > Then all you need is a rudimentary quoting. > > > > > > > > Yes, but the question still remains what that rudimentary quoting > > > > is - > > > i.e. > > > > I can see how to quote spaces which appear in elements of argv, > > > > but I cannot see how to quote double quotes! > > > > > > This should help: > > > https://blogs.msdn.microsoft.com/twistylittlepassagesallalike/2011/0 > > > 4/23/e veryone-quotes-command-line-arguments-the-wrong-way/ > > > > This provides documentation for how Microsoft implementations do it, not > how Cygwin does it. The Cygwin DLL is responsible for determining how a > Cygwin process gets argc and argv from GetCommandLineW. > > That's correct but I read your question as "how do I start executables > linked against Cygwin from another Windows process" That's the correct reading of my question! > To do that, you need to convert the argument list/array into the stupid > Windows format because that's what the Cygwin process will expect. This is not correct - both by reading the code and by testing. If you put this into the program caller.c I posted previously in thread which is intended to start with argv[1] being the literal string a\\b (i.e. 4 characters) commandLine = "callee \"a\\\\b\""; and then if callee.c is compiled with i686-w64-mingw32-gcc (Microsoft-world - escaping rules according to MSDN): $ ./caller argc = 2 argv[0] = callee argv[1] = a\\b with argv[1] correctly given in Microsoft's escaping. But if you compile callee.c with gcc (Cygwin-world), you get: $ ./caller argc = 2 argv[0] = callee argv[1] = a\b With the Cygwin DLL applying its interpretation of the escaping (treating \\ within a quoted parameter as an escaped single backslash), and quite clearly not MSDN's (treating \\ as two backslash characters because it's no followed by a double-quote). As an aside, if you have CYGWIN=noglob, you will actually get the same output as the native Windows case with two backslashes (more evidence, if you still need it, about how my question is everything to do with the Cygwin DLL, and nothing to do with MSDN and Microsoft's escaping rules). There's also the small matter of Cygwin's @file trick for reading command line arguments from files (i.e. an extra escaping rule not indicated in MSDN because it's not part of Windows) - this time have commandLine = "@test", run echo foo>test and this time with a Microsoft-compiled callee, you'll get argv[1] = @test and with a Cygwin-compiled one, you'll get argv[1] = foo > > > My line of thought is that Cygwin can't get anything which Windows > > > can't send it. So the first step to solve this mess is to make sure > > > the arguments which you send to CreateProcess() are correct. > > > > > > The next step would be to write a small C utility which dumps it's > > > > arguments, so you can properly debug all kinds of characters. > > > > See later email, but IMHO the conversion is something Cygwin should have > precisely documented, not determined by brittle experimentation. > > Ah... no. You're mixing two or three things. Let me enumerate: > > 1. You have to give your OS (Windows or Unix) the information which > process you want to start and which arguments to pass. Unix has two ways > (string array and single string), Windows has only single string. Which system call in Unix allows you to start a process by giving a single string instead of an array of arguments (or a series of parameters)? > 2. The OS will put the information into a structure of some kind and pass > that to the new process. > 3. If you have a shell (CMD.exe, bash, etc), they will take the structure > and parse it according to some rules. They will then convert the result > again into an OS call. > 4. The C runtime of your executable will know where to get the OS > structure and how to turn the structure into char ** argv. > Where is Cygwin in all this? It's part of step #3. Cygwin emulates exec() > and similar Unix OS functions which an emulated shell like BASH will use. > Which means Cygwin code in the DLL is irrelevant if you don't have a Unix > shell somewhere in your process chain. No, Cygwin is loosely part of step #3 and definitely the whole of #4. If you invoke a Cygwin process from a native process, the Cygwin DLL does the work of #4, not the C runtime. Step #3 is entirely irrelevant to my problem because there is no shell involved. > If you just want to execute a Cygwin process (= Windows process which > includes the Cygwin.dll), you need to know #1, #2 and #4. Indeed - which basically was my original question. Precisely how Cygwin deals with the conversion in Step 4. 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
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |