X-Recipient: archive-cygwin AT delorie DOT com X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL,BAYES_00,SPF_SOFTFAIL X-Spam-Check-By: sourceware.org Message-ID: <4B7E94F9.6040602@byu.net> Date: Fri, 19 Feb 2010 06:41:13 -0700 From: Eric Blake User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.23) Gecko/20090812 Thunderbird/2.0.0.23 Mnenhy/0.7.6.666 MIME-Version: 1.0 To: cygwin AT cygwin DOT com, piotr DOT krukowiecki DOT news AT gmail DOT com Subject: Re: CreateProcess() - executed program gets different argument depending if it's compiled with gcc (cygwin) or cl (VS)? References: <98f79fac1002180955m1ddea014id0b27cc3b909a17a AT mail DOT gmail DOT com> <4B7D80B3 DOT 4000300 AT cygwin DOT com> <98f79fac1002181224g7987690dn6822d025d1a59405 AT mail DOT gmail DOT com> <4B7DA704 DOT 1080709 AT cygwin DOT com> <98f79fac1002190437g5fec3138mb2c7e24d8f03212a AT mail DOT gmail DOT com> <98f79fac1002190452h2d99cf0aqf5ca72d952521da0 AT mail DOT gmail DOT com> In-Reply-To: <98f79fac1002190452h2d99cf0aqf5ca72d952521da0@mail.gmail.com> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enig53BBE7AA39F5B609FC4923C6" X-IsSubscribed: yes 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 --------------enig53BBE7AA39F5B609FC4923C6 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable According to Piotr Krukowiecki on 2/19/2010 5:52 AM: >>>>> '\' is an escape character in C, Unix, and Linux. In Windows, it's a >>>>> path separator. Use '/' instead when working with Cygwin and you'll >>>>> avoid allot of problems. Better yet, use POSIX paths exclusively. > [...] >> I don't know which program (cygwin/windows) is going to be executed. >> Do I have to check before execution if the program is compiled under >> cygwin and implement different logic in that case? From what I >> understood so far this is the only way? I haven't followed your queries closely (since you keep replying to yourself). But it all boils down to: what shell are you using, with its particular quoting rules what quoting does the shell strip before passing arguments to a child what quoting does a child do given arguments from the parent If your shell is cmd.exe, quoting rules are (IMO) weird, but well-defined according to microsoft's rules. Something along the lines of using "", and \ is special in some situations but not others and depending on whether there were an even or odd number of them. I don't use cmd.exe, so I won't bother trying to summarize those rules. If you use tcsh, quoting rules are not identical to POSIX rules, but certainly well-documented in the man page. If your shell is anything else (bash, zsh, ksh), quoting rules follow POSIX, where "", '', and \ have three distinct environments (inside '', \ is a normal character, inside "", \ is special in front of only ", \, `, and $). For a cygwin process invoking a cygwin process, all quoting is stripped per the rules of the shell, and the child sees the resulting arguments without quotes. Cygwin bypasses CreateProcess to allow arbitrary length command lines, so it does not have to worry about stupid windows rules. For a windows process invoking a cygwin process, windows rules are followed (the shell doesn't strip anything, but calls CreateProcess as-is); but then the cygwin1.dll strips the quoting before main() according to windows rules so that the cygwin process sees the resulting arguments without quotes. This way, cygwin apps themselves NEVER have to worry about quoting, regardless of who the parent process was. For a windows process invoking a windows process, windows rules are followed (roughly: cmd.exe passes everything, quotes and all, into CreateProcess, and the child app is responsible for stripping them). For a cygwin process invoking a windows process, all quoting is stripped by the shell before the exec() call, but then cygwin1.dll re-adds quoting according to Windows rules so that the resulting windows app sees quoting as if from cmd.exe. But nowhere in this do I see any way that the compiler used could affect how quoting is handled. --=20 Don't work too hard, make some time for fun as well! Eric Blake ebb9 AT byu DOT net --------------enig53BBE7AA39F5B609FC4923C6 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (Cygwin) Comment: Public key at home.comcast.net/~ericblake/eblake.gpg Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkt+lPsACgkQ84KuGfSFAYAiUQCgvyuzpYdKTDj2Txfe8K9j8DWi b7gAoLQFmGoEVxVbLewuGl+Ju6UlqF8i =vmff -----END PGP SIGNATURE----- --------------enig53BBE7AA39F5B609FC4923C6--