X-Recipient: archive-cygwin AT delorie DOT com X-SWARE-Spam-Status: No, hits=0.0 required=5.0 tests=AWL,BAYES_00,SARE_MSGID_LONG40,SPF_PASS X-Spam-Check-By: sourceware.org MIME-Version: 1.0 Date: Thu, 18 Feb 2010 18:55:36 +0100 Message-ID: <98f79fac1002180955m1ddea014id0b27cc3b909a17a@mail.gmail.com> Subject: CreateProcess() - executed program gets different argument depending if it's compiled with gcc (cygwin) or cl (VS)? From: Piotr Krukowiecki To: cygwin AT cygwin DOT com Content-Type: text/plain; charset=ISO-8859-1 X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Hello, In short, I have a problem with passing "\\127.0.0.127\foo.cxx" argument to a called program: - if the executed program is compiled with cygwin's gcc the program receives \127.0.0.127\foo.cxx (just one backslash at the begining). - if it's compiled with cl it gets \\127.0.0.127\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? Details: 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 "\\127.0.0.127\foo.cxx" /cygdrive/f/t/dumpargs_gcc \127.0.0.127\foo.cxx Command: F:\t\dumpargs_cl.exe "\\127.0.0.127\foo.cxx" F:\t\dumpargs_cl.exe \\127.0.0.127\foo.cxx ------------- As you can see dumpargs_gcc receives "\127.0.0.127\foo.cxx" and dumpargs_cl receives "\\127.0.0.127\foo.cxx". In my opinion, based on "Parsing C++ Command-Line Arguments" (http://msdn.microsoft.com/en-us/library/17w5ykft%28VS.100%29.aspx), 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 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 #include void runCommand(char * command) { STARTUPINFO si; PROCESS_INFORMATION pi; 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 " \"\\\\127.0.0.127\\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: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple