Still no luck on command line parse
lawson_whitney at juno.com
lawson_whitney at juno.com
Sun Feb 3 11:45:12 CST 2002
On Sun, 3 Feb 2002, Francois Gouget wrote:
> This seems all very logical and I am pleased to note that native and
> builtin msvcrt behave identically. Note that your test above should
> really print GetCommandLine() too.
>
lcc-win uses crtdll, and I don't have a usable one of those, but builtin
crtdll forwards everything anyway, and it actually works with native
msvcrt if you ask it to.
>
> Well, the thing you have to understand is that Windows and Unix
> handle things very differently. On Unix the new process does not receive
> a command line but a string array. Argc/argv just point to that data. On
> Windows the new process receives a single string which is the raw
> command line.
> So what happens in Wine is that when a process invokes CreateProcess?
> The command line is broken up into argc/argv, passed down to exec, then
> the Wine startup code rebuilds the command line from there. If your
> process has a main then it gets the original argc/argv (almost, Wine
> still has to remove the wine specific options), and if it has a WinMain,
> then it gets the rebuilt command line.
main gets it as constructed by the C runtime, isn't it?
> And if you invoke Wine from the command line or from any Unix
> process, there is no 'original commandline'. But Wine will rebuild one
> from argc/argv just like it always does. Now, the only information loss
> is at the level of the spaces between the arguments on the command line.
> See this email for more details:
> http://www.winehq.com/hypermail/wine-devel/2002/01/0240.html
>
>
> > Unlike the unix shell, they only preserve spaces
> > in an argument quoted by \", and treat " as an ordinary character.
>
> Not true. Here is a test I did in Windows:
>
> c:\>main.exe "quoted string"
> GetCommandLine=[main.exe "quoted string"]
> main -> argc=2
> 0 [main.exe]
> 1 [quoted string]
> c:\>main.exe \"quoted string\"
> GetCommandLine=[main.exe \"quoted string\"]
> main -> argc=3
> 0 [main.exe]
> 1 ["quoted]
> 2 [string"]
>
> Windows handles " and \" just like the Unix shells do.
>
In effect that is the same as the unix shell + wine, I think.
>
> See also:
> http://www.winehq.com/hypermail/wine-devel/2001/09/0004.html
>
>
> --
> Francois Gouget fgouget at free.fr http://fgouget.free.fr/
> Linux: It is now safe to turn on your computer.
>
Hmmm, I think I see the problem:
[whit at giftie cmdl]$ wine /gp/windose/Program\ Files/cmdl.exe
/"/gp/windose/Program Files/cmdl.exe"/
arg 0: //gp/windose/Program Files/cmdl.exe/
[whit at giftie cmdl]$ wine 'c:\Program Files\cmdl.exe' 'hi there'
/"c:\Program Files\cmdl.exe" "hi there"/
arg 0: /c:\Program Files\cmdl.exe/
arg 1: /hi there/
[whit at giftie cmdl]$
Wine will let you run a program by its unix path, but if you do the
program will see in GetCommandLine and argv[0] a path it can't make
sense of. I'm not at all sure that's a bug, but it might not be
intuitive to somebody accustomed to windose.
#include <stdio.h>
#include <win.h>
main(int argc, char **argv)
{
int i;
printf("/%s/\n",GetCommandLine());
for (i = 0; i < argc; i++)
printf("arg %d: /%s/\n", i, argv[i]);
}
lcclnk.exe just hangs if you miss an include. I'd rather see "implicit
definition" or "Undefined reference" any day.
Lawson
More information about the wine-users
mailing list