Why does CYGWIN double the backslash in execvp()?

A L al20878@gmail.com
Thu Feb 26 16:30:00 GMT 2015


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:\\";
  args[2] = "DIR C:\\.";
  args[3] = 0;
  printf("Command = \"%s %s %s\"\n", args[0], args[1], args[2]);
  xargs = (char**) &args;
  execvp(args[0], xargs);
  return 0;

 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?


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