From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22807 invoked by alias); 10 May 2016 17:02:36 -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 22794 invoked by uid 89); 10 May 2016 17:02:35 -0000 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 Received: from outmail149055.authsmtp.co.uk (HELO outmail149055.authsmtp.co.uk) (62.13.149.55) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 10 May 2016 17:02:26 +0000 Received: from mail-c232.authsmtp.com (mail-c232.authsmtp.com [62.13.128.232]) by punt21.authsmtp.com (8.14.2/8.14.2/) with ESMTP id u4AH2OGM016057; Tue, 10 May 2016 18:02:24 +0100 (BST) Received: from romulus.metastack.com (114.212-105-213.static.virginmediabusiness.co.uk [213.105.212.114]) (authenticated bits=0) by mail.authsmtp.com (8.14.2/8.14.2/) with ESMTP id u4AH2MKk020828 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 10 May 2016 18:02:23 +0100 (BST) Received: from Bug (ip4d16c703.dynamic.kabel-deutschland.de [77.22.199.3]) (authenticated bits=0) by romulus.metastack.com (8.14.2/8.14.2) with ESMTP id u4AH2LFr027247 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO); Tue, 10 May 2016 18:02:22 +0100 From: "David Allsopp" To: "'Aaron Digulla'" , References: <6533-5731e280-9-60079180@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 17:02:00 -0000 Message-ID: <000001d1aadd$b8649970$292dcc50$@cantab.net> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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-SW-Source: 2016-05/txt/msg00110.txt.bz2 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. >=20 > 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 t= his into the program caller.c I posted previously in thread which is intend= ed to start with argv[1] being the literal string a\\b (i.e. 4 characters) commandLine =3D "callee \"a\\\\b\""; and then if callee.c is compiled with i686-w64-mingw32-gcc (Microsoft-world= - escaping rules according to MSDN): $ ./caller argc =3D 2 argv[0] =3D callee argv[1] =3D a\\b with argv[1] correctly given in Microsoft's escaping. But if you compile ca= llee.c with gcc (Cygwin-world), you get: $ ./caller argc =3D 2 argv[0] =3D callee argv[1] =3D a\b With the Cygwin DLL applying its interpretation of the escaping (treating \= \ within a quoted parameter as an escaped single backslash), and quite clea= rly not MSDN's (treating \\ as two backslash characters because it's no fol= lowed by a double-quote). As an aside, if you have CYGWIN=3Dnoglob, you wil= l actually get the same output as the native Windows case with two backslas= hes (more evidence, if you still need it, about how my question is everythi= ng to do with the Cygwin DLL, and nothing to do with MSDN and Microsoft's e= scaping rules). There's also the small matter of Cygwin's @file trick for reading command l= ine arguments from files (i.e. an extra escaping rule not indicated in MSDN= because it's not part of Windows) - this time have commandLine =3D "@test"= , run echo foo>test and this time with a Microsoft-compiled callee, you'll = get argv[1] =3D @test and with a Cygwin-compiled one, you'll get argv[1] = =3D 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 >=20 > > > 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. >=20 > Ah... no. You're mixing two or three things. Let me enumerate: >=20 > 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 yo= u invoke a Cygwin process from a native process, the Cygwin DLL does the wo= rk of #4, not the C runtime. Step #3 is entirely irrelevant to my problem b= ecause there is no shell involved. > If you just want to execute a Cygwin process (=3D 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 dea= ls 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