This is the mail archive of the
cygwin
mailing list for the Cygwin project.
Why does CYGWIN double the backslash in execvp()?
- From: A L <al20878 at gmail dot com>
- To: cygwin at cygwin dot com
- Date: Wed, 25 Feb 2015 23:12:31 -0500
- Subject: Why does CYGWIN double the backslash in execvp()?
- Authentication-results: sourceware.org; auth=none
Hello,
Here's code that (if BUG is defined) does not work because it looks
like Cygwin doubles the backslash in args[2] when that gets passed to
CMD. If I add a trailing period (#undef BUG), the preceding backslash
does not get doubled, the command runs as it is supposed to.
Why there's an additional backslash in the first case? Should not
args be passed "as is"?
Running under strace confirms the extraneous addition.
---
#include <stdio.h>
#include <unistd.h>
#define BUG
int main()
{
const char* args[4];
char** xargs;
args[0] = "/cygdrive/c/windows/system32/cmd.exe";
args[1] = "/c";
#ifdef BUG
args[2] = "DIR C:\\";
#else
args[2] = "DIR C:\\.";
#endif
args[3] = 0;
printf("Command = \"%s %s %s\"\n", args[0], args[1], args[2]);
xargs = (char**) &args;
execvp(args[0], xargs);
return 0;
}
---
Compare:
1834 22106 [main] a 7152 child_info_spawn::worker: pid 7152,
prog_arg /cygdrive/c/windows/system32/cmd.exe, cmd line
C:\windows\system32\cmd.exe /c "DIR C:\\")
1595 19614 [main] a 4356 child_info_spawn::worker: pid 4356,
prog_arg /cygdrive/c/windows/system32/cmd.exe, cmd line
C:\windows\system32\cmd.exe /c "DIR C:\.")
Maybe I'm doing something wrong, any ideas?
Thanks,
AL
--
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