Mail Archives: cygwin/2003/07/20/20:21:04
I observe some weirdness in argv/argc parsing in 1.3.22 (the current
cygwin).
Consider the attached C program and compile it with and without cygwin
like this:
$ gcc -Wall -g argtest.c -o argtest-cygwin
$ gcc -Wall -g -mno-cygwin argtest.c -o argtest-mingw
when passed arguments explicitly, they work reasonably (= like on linux)
$ ./argtest-... "4 4" '5 5'
* argc=3
[path/argtest-...]
[4 4]
[5 5]
$
when called from a shell with the arguments in a variable, it is weird
(same weirdness as on linux, so, I guess, I need to RTFM):
arg='"4 4" '"'5 5'"
./argtest-... $arg
* argc=5
[d:\sds\c\argtest-mingw.exe]
["4]
[4"]
['5]
[5']
(I expected the same output as with explicit args).
Now the juice: when I run these under gdb, I get _different_ output
with the same arguments:
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']
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]
comments?
--
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>
Those who can't write, write manuals.
--=-=-=
Content-Type: text/c
Content-Disposition: attachment; filename=argtest.c
Content-Description: C test program
#include <stdio.h>
int main (int argc, char *argv[]) {
printf(" * argc=%d\n",argc);
while (argc--) printf("[%s]\n",*argv++);
return 0;
}
--=-=-=
Content-Type: text/sh
Content-Disposition: attachment; filename=argtest
Content-Description: shell script test
#!/bin/sh
args='"4 4" '"'5 5'"
echo $args
./argtest-cygwin.exe ${args}
./argtest-mingw.exe ${args}
--=-=-=
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 -