Mail Archives: cygwin/2003/07/20/20:50:48
Compile the attached C program with
$ gcc -std=c99 -Wall -g argtest.c -o argtest-cygwin
$ gcc -std=c99 -Wall -g -mno-cygwin argtest.c -o argtest-mingw
and run it with
$ args='"4 4" '"'5 5'"
$ echo $args
$ ./argtest-cygwin.exe "${args}" a
"4 4" '5 5'
* argc=3
[./argtest-cygwin]
["4 4" '5 5']
[a]
* argc=2
[./argtest-cygwin]
["4 4" '5 5']
* argc=1
[./argtest-cygwin]
$ ./argtest-mingw.exe "${args}" a
* argc=3
[d:\sds\c\argtest-mingw.exe]
["4 4" '5 5']
[a]
* argc=4
[d:\sds\c\argtest-mingw.exe]
[4 4]
['5]
[5']
* argc=4
[d:\sds\c\argtest-mingw.exe]
[4]
[4]
['5]
* argc=3
[d:\sds\c\argtest-mingw.exe]
[4]
[4]
* argc=2
[d:\sds\c\argtest-mingw.exe]
[4]
* argc=1
[d:\sds\c\argtest-mingw.exe]
as you can see, mingw execv() splits argv()!!!
(the obvious workaround is to quote the argv args that contain spaces)
This appears to be a known mingw bug (at least since February 2002),
but somehow it is still there...
Now, the biggest trouble is that this bites cygwin gdb which passes
different arguments to cygwin and mingw executables:
(gdb) run arg 1 2 "3" "4 4" '5 5'
Starting program: /cygdrive/d/sds/c/argtest-mingw.exe arg 1 2 "3" "4 4" '5 5'
* argc=8
[d:\sds\c\argtest-mingw.exe]
[arg]
[1]
[2]
[3]
[4 4]
['5]
[5']
(gdb) run arg 1 2 "3" "4 4" '5 5'
Starting program: /cygdrive/d/sds/c/argtest-cygwin.exe arg 1 2 "3" "4 4" '5 5'
* argc=7
[/cygdrive/d/sds/c/argtest-cygwin]
[arg]
[1]
[2]
[3]
[4 4]
[5 5]
--
Sam Steingold (http://www.podval.org/~sds) running w2k
<http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/>
<http://www.mideasttruth.com/> <http://www.palestine-central.com/links.html>
When we write programs that "learn", it turns out we do and they don't.
--=-=-=
Content-Type: text/c
Content-Disposition: attachment; filename=argtest.c
Content-Description: C test program
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
int main (int argc, char *argv[]) {
printf(" * argc=%d\n",argc);
for (int i=0; i<argc; i++) printf("[%s]\n",argv[i]);
if (argc>1) {
argv[argc-1] = NULL;
execv(argv[0],argv);
perror(argv[0]);
return 1;
} else
return 0;
}
--=-=-=
Content-Type: text/plain; charset=us-ascii
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
--=-=-=--
- Raw text -