This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: CreateProcess() - executed program gets different argument depending if it's compiled with gcc (cygwin) or cl (VS)?

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.

Don't work too hard, make some time for fun as well!

Eric Blake   

Attachment: signature.asc
Description: OpenPGP digital signature

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]