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]

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


In short, I have a problem with passing "\\\foo.cxx"
argument to a called program:

- if the executed program is compiled with cygwin's gcc the program
receives \\foo.cxx (just one backslash at the begining).
- if it's compiled with cl it gets \\\foo.cxx (double
backslash - what I expected)

I suspect cygwin incorrectly mangles backslashes in this case - or
maybe I'm quoting it incorrectly, or it is Windows fault?


I have a short program (source code for all programs attached at the
end) that just prints it's argv on standard output. I compile this
program twice: once with gcc from cygwin and once with VS cl.
I have another small program that executes those two programs using
CreateProcessA() and passes the same argument to them. Yet the
programs show unexpected difference (ignoring the acceptable
difference in argv[0]). Please see the log:

$ cl dumpargs.c /Fedumpargs_cl.exe
$ gcc -Wall dumpargs.c -o dumpargs_gcc.exe
$ gcc -Wall -o createprocess.exe createprocess.c
$ ./createprocess.exe

Command: F:\t\dumpargs_gcc.exe  "\\\foo.cxx"

Command: F:\t\dumpargs_cl.exe  "\\\foo.cxx"

As you can see dumpargs_gcc receives "\\foo.cxx" and
dumpargs_cl receives "\\\foo.cxx".

In my opinion, based on "Parsing C++ Command-Line Arguments"
the cl version is correct.

Could you please explain if this is cygwin/microsoft or my bug?

Below I'm pasting source code for the createprocess and dumpargs program:

--- cut --- dumpargs.c --- cut ---
#include <stdio.h>
int main(int argc, char **argv) {
    int i;
    for (i = 0; i < argc; ++i) {
        printf("%s\n", argv[i]);
    return 0;
--- cut --- cut --- cut ---

--- cut --- createprocess.c --- cut ---
#include <windows.h>
#include <stdio.h>
void runCommand(char * command) {

    ZeroMemory(&pi, sizeof(pi));
    ZeroMemory(&si, sizeof(si));
    si.cb = sizeof(si);

    printf("\nCommand: %s\n", command);

    CreateProcessA(NULL, command, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi);
    WaitForSingleObject(pi.hProcess, INFINITE);

    CloseHandle( pi.hProcess );
    CloseHandle( pi.hThread );
#define COMMAND_ARGS " \"\\\\\\foo.cxx\" "
int main() {
    runCommand("F:\\t\\dumpargs_gcc.exe " COMMAND_ARGS);
    runCommand("F:\\t\\dumpargs_cl.exe " COMMAND_ARGS);
    return 0;

Piotr Krukowiecki

Problem reports:
Unsubscribe info:

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