Still no luck on command line parse

Francois Gouget fgouget at free.fr
Sun Feb 3 14:19:30 CST 2002


On Sun, 3 Feb 2002 lawson_whitney at juno.com wrote:

> On Sun, 3 Feb 2002, Francois Gouget wrote:
[...]
> >    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?

   Which main?
 * the main of a Unix application. The C runtime invokes main so it gets
the pointers from it after a fashion. But I am pretty sure these point
to a memory block that was initialized by the kernel itself
 * the main of a Winelib application. This one gets it from Wine. More
precisely it gets it from scheduler/process.c:build_argv()
 * and the WinMain of a Winelib application gets its command line from
memory/environ.c:ENV_BuildCommandLine(), which builds it from the result
of build_argv()


> 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.

   If you have a 'z:' drive that points to /, then the first path is
valid. Except if Wine changes the current drive or chooses another
current driver for some reason... For instance here /home/fgouget
corresponds to y:\ and z:\home\fgouget so I am not sure which one Wine
would actually choose on startup. And if it chooses y:\, then
/home/fgouget/foo.exe would not be a valid path anymore.


--
Francois Gouget         fgouget at free.fr        http://fgouget.free.fr/
     The software said it requires Win95 or better, so I installed Linux.





More information about the wine-users mailing list