From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 76550 invoked by alias); 10 May 2016 13:30:16 -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 76425 invoked by uid 89); 10 May 2016 13:30:15 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,SPF_PASS autolearn=ham version=3.3.2 spammy=lastly, U*david, sk:david@a, sk:davida X-HELO: mail.hepe.com Received: from sbb-mail.hepe.com (HELO mail.hepe.com) (78.47.220.235) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Tue, 10 May 2016 13:30:04 +0000 Received: from sbb-sogo.hepe.com ([172.22.225.144]) by mail.hepe.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1b07jc-0003sY-Km for cygwin@cygwin.com; Tue, 10 May 2016 13:30:00 +0000 Received: from sogo by sbb-sogo.hepe.com with local (Exim 4.84_2) (envelope-from ) id 1b07jc-0003sS-Bv for cygwin@cygwin.com; Tue, 10 May 2016 13:30:00 +0000 content-type: text/plain; charset="utf-8" in-reply-to: from: "Aaron Digulla" X-Forward: 46.140.173.26 Date: Tue, 10 May 2016 13:30:00 -0000 to: =?utf-8?q?cygwin=40cygwin=2Ecom?= MIME-Version: 1.0 message-id: <6533-5731e280-9-60079180@7271027> subject: =?utf-8?q?RE=3A?= Formatting command line arguments when starting a Cygwin process from a native process User-Agent: SOGoMail 2.3.10 content-transfer-encoding: quoted-printable X-IsSubscribed: yes X-SW-Source: 2016-05/txt/msg00108.txt.bz2 Am Montag, 09. Mai 2016 17:19 CEST, David Allsopp schr= ieb: > 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/04/2= 3/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 Cyg= win process gets argc and argv from GetCommandLineW. That's correct but I read your question as "how do I start executables link= ed against Cygwin from another Windows process" To do that, you need to convert the argument list/array into the stupid Win= dows format because that's what the Cygwin process will expect. > > 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 a= rray and single string), Windows has only single string. 2. The OS will put the information into a structure of some kind and pass t= hat to the new process. 3. If you have a shell (CMD.exe, bash, etc), they will take the structure a= nd parse it according to some rules. They will then convert the result agai= n 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() a= nd similar Unix OS functions which an emulated shell like BASH will use. Wh= ich means Cygwin code in the DLL is irrelevant if you don't have a Unix she= ll somewhere in your process chain. If you just want to execute a Cygwin process (=3D Windows process which inc= ludes the Cygwin.dll), you need to know #1, #2 and #4. > > PS: I always point people to string list/array type methods to create > > processes which fix all the problems with spaces and odd characters > > (quotes, umlauts, etc). It seems that Windows doesn't have such a method > > to create processes. Which kind of makes sense; Windows is very, very > > mouse centered. > > I fail to see the connection with mice! What Windows (NT) does have is a = legacy where the decision on how to convert a command line to a list/array = of arguments is determined per-process (and so not the responsibility of co= mmand line shells) vs Unix which puts the burden of converting a single com= mand line to the array on the shell instead. Nominally, the Windows way is = more flexible, though I don't think that flexibility is actually useful (es= pecially if you look at the comments in the command line -> argv conversion= in Microsoft's C Runtime library!). Using single strings to run commands causes all kinds or problems. It's a b= rittle API, which you should avoid. It kind of feels more simple but it's t= he "too simple" kind which Einstein mentioned ("You should make things as s= imple as possible. But not more simle.") Think of it that way: Your executable gets the arguments as a string array.= On the parent process side, Unix allows you to create a process with an ar= ray of strings. That's a natural API which doesn't need any kind of convers= ion (maybe you need to copy the strings but that's it). If you convert from and to a single string all the time, you need a way to = quote and escape. So this is more error prone than the plain array solution. And lastly: If everyone would always use arrays, we wouldn't have this long= , tedious discussion. Regards, -- Aaron "Optimizer" Digulla a.k.a. Philmann Dark "It's not the universe that's limited, it's our imagination. Follow me and I'll show you something beyond the limits." http://blog.pdark.de/ -- 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