dlls/msvcrt: process.c (msvcrt-popen-1)

Jaco Greeff jaco at puxedo.org
Fri Nov 1 12:41:21 CST 2002

On 01 Nov 2002 08:40:20 -0800, Alexandre Julliard <julliard at winehq.com> wrote :
> No, it's wrong. You should be using the Windows API (CreateProcess
> etc.) not the Unix popen(). Then you can build a proper MSVCRT_FILE.

Sorry, I had a few beers tonight ;) Ok, I just remembered what my concerns
were about using CreateProcess initially when I looked at MSDN:

CreateProcess executes a Windows executable with parameters, whereas _popen
executes as shell, ie. you can do stuff like _popen("dir/w") which will
return an open file in which you can read the directory contents from. In
essence under Windows, this gets executed at "cmd.exe /C dir/w". 

Now using CreatePorcess we can potentially do the same, provided that the
executable (command interpreter) resides in your path. From MSDN:

"The string can specify the full path and file name of the module to execute
or it can specify a partial name. In the case of a partial name, the
function uses the current drive and current directory to complete the

Now wera are faced with a problem in that wcmd is not a pure Windows
application and it doesn't reside in your Windows filesystem, rather it is
in your *nix path. 

In the case of _popen, a file-handle is returned which allows you to either
read or write to the application unsing the normal fwrite/fprintf/etc.
commands. CreateProcess has an information structure containing the
following information:

typedef struct _PROCESS_INFORMATION {
  HANDLE hProcess;
  HANDLE hThread;
  DWORD dwProcessId;
  DWORD dwThreadId;

I don't see any clear way of doing,

1. Converting the above structure into something usable, eg. MSVCRT_FILE
2. Actually allowing us to read or write to the application

Potentially the magic lies in the current Wine CreateProcess implementation,
I'll have a look at it. Is doing this really feasable using the
CreateProcess family? In essence a HANDLE will map back to an fd with the
wine implementation (rather we can get an fd for a HANDLE), but can this be
used to read/write to the process? The first obstacle however, will be in
having a clean way to get wcmd going if it doesn't reside in C:\. Maybe it
should be there and should be installed like notepad.exe for example?

Some questions, and yes I'm slow tonight... :) I think that just by typing
this some concerns have been aleviated so excuse my rumblings but just check
the logic.


More information about the wine-devel mailing list