Why does CYGWIN double the backslash in execvp()?

Peter Rosin peda@lysator.liu.se
Fri Feb 27 09:22:00 GMT 2015

On 2015-02-27 06:03, A L wrote:
> Thank you for your response.  It may sound plausible but:
>> you tell Cygwin that you want posix semantics
> I can't remember seeing that posix semantics require a C library call
> to modify arguments in the way the shell does;  since when cygwin a
> shell?

E.g. windows processes does not expect the shell to handle wildcards.

>> split arg 2 into two args: "DIR" and "C:\\"
> and why does it make a difference, all of a sudden?  (posix rules no
> longer apply to more than 2 arguments?)  also, if "\\" is followed by
> an additional space, "DIR C:\\ ", then it begins to work as well.

It makes a difference because cmd has non-posixy handling of its command
line, like most windows tools. What I think happens is that since you
specify a full posix path to cmd, you get posix semantics and none of
the Windows compatibilty crap kicks in.

On top of that, cmd command line handling is not like other Windows
tools and while I didn't think there were any exceptions to how Cygwin
handled windows processes, apparently there was this exception.

>> Cygwin cannot make exceptions for individual applications
> right!  because cygwin does already know a lot about cmd.exe and
> command.com and treats them very specially in case of a "/c" switch
> followed by exactly one argument!  take a look at spawn.cc.

Oh, you're looking at the code. Then you are ahead of me. I thought
you wanted suggestions for why it didn't work.

I think the code you are looking at is probably sidestepped when you
say /cygdrive/c/.../cmd.exe (posix). If you instead say
c:/.../cmd.exe (windows) the code is in the loop (and it works too).

> btw, on linux, strace for execl() shows no substitution of a lone
> backslash passed in an argument... not posix complying, too?

Do get ridiculous. Linux doesn't have to cope with the insanities
of Windows.


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

More information about the Cygwin mailing list