From: Julien L. <ju...@fa...> - 2007-05-29 09:16:33
|
(NB: I'm replying to a post in another thread, because for some reason, even if I did receive a post ack, when I create a new thread my post mysteriously never gets through. I'm sorry.) Vincent Torri's mail on WinMain, CommandLineToArgvW and GetCommandLineA/W made me notice the following "bug" which can be tested with the following code: == BOF test1.c == #include <stdio.h> #include <windows.h> int APIENTRY WinMain (HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { printf("lpCmdLine (%d) = **%s**\n", strlen(lpCmdLine), lpCmdLine); // strip right trailing spaces CHAR* cstrip = lpCmdLine + strlen(lpCmdLine) - 1; while (*cstrip == ' ') *cstrip-- = 0; printf("stripped (%d) = **%s**\n\n", strlen(lpCmdLine), lpCmdLine); return 0; } == EOF test1.c == I've noticed that the mingw-runtime will: - often add at least a trailing space when using several commands in a row. - convert/remove quotes in some cases. With the folowing commands (please note that spaces can be important) $ gcc test1.c -o test1.exe $ ./test1.exe "toto1" $ ./test1.exe 'toto2' $ ./test1.exe toto3&& ./test1.exe toto4 $ ./test1.exe toto5 && ./test1.exe toto6 I get the selected following results: With console MSYS shell (TERM=cygwin; MSYSTEM=MINGW32) julienlecomte@PUMILIO ~/procrast $ ./test1.exe "toto1" lpCmdLine (6) = **toto1 ** stripped (5) = **toto1** $ ./test1.exe 'toto2' lpCmdLine (6) = **toto2 ** stripped (5) = **toto2** $ ./test1.exe toto3&& ./test1.exe toto4 lpCmdLine (6) = **toto3 ** stripped (5) = **toto3** lpCmdLine (6) = **toto4 ** stripped (5) = **toto4** $ ./test1.exe toto5 && ./test1.exe toto6 lpCmdLine (6) = **toto5 ** stripped (5) = **toto5** lpCmdLine (6) = **toto6 ** stripped (5) = **toto6** With console cmd.exe: M:\home>test1.exe "toto1" lpCmdLine (7) = **"toto1"** stripped (7) = **"toto1"** M:\home>test1.exe 'toto2' lpCmdLine (7) = **'toto2'** stripped (7) = **'toto2'** M:\home>test1.exe toto3&& test1.exe toto4 lpCmdLine (5) = **toto3** stripped (5) = **toto3** lpCmdLine (5) = **toto4** stripped (5) = **toto4** M:\home>test1.exe toto5 && test1.exe toto6 lpCmdLine (12) = **toto5 ** stripped (5) = **toto5** lpCmdLine (5) = **toto6** stripped (5) = **toto6** I might be able to understand why quotes are converted (toto1 and toto2 for example) depending on console box as this might be an effect of the shell before creating the process. On the other hand, I can't understand why behavior isn't the same in toto5 test case since I tend to believe that any command line will (should?) always be right space trimmed. I believe that mingw-runtime should trim the spaces on the right before calling WinMain and that results should be more consistent under cmd.exe. Should we or not modify mingw-runtime to trim those spaces? |