Can MinGW translate calls to popen(3)?

Richard W.M. Jones rjones at redhat.com
Thu Sep 24 08:30:57 UTC 2009


On Sat, Sep 19, 2009 at 11:30:59AM +0530, Harry Simons wrote:
> Hello,
> 
> I have a C program that builds and runs fine on my Fedora 11 box. This program uses popen as follows:
> 
>      FILE *pipe = popen("perl - ", "w");
[...]

> I would like to know if MinGW can help me:
>    1. cross-compile the above C program (on my Fedora 11 for the
>       Windows platform),

Yes, but ..

>    2. without having to replace the above call to popen by less than
>        ideal Windows counterparts like _popen (which pops up an ugly
>        CMD console window!), or CreatePipe, or CreateNamedPipe, etc.

No.

You have to program against the Win32 API.  There's no POSIX
translation layer in MinGW.

Having said that, there are some things which can help:

(a) Use a higher-level portable API, eg. glib, APR, NSPR ...  I'm sure
one of these has a replacement for popen functionality.  These
libraries often help you port to other platforms too, so it can be
useful to modify your code to use them.

(b) Use the replacement functions from Gnulib.  Sadly Gnulib doesn't
have a popen replacement yet, but it does have replacements for many
other POSIX and libc functions.

  http://www.gnu.org/software/gnulib/manual/gnulib.html

(c) Look at MSDN's example using pipes.  The Win32 API is horrible,
but it's still possible to use pipes and redirect, although nowhere
near as elegant and simple as in POSIX:

  http://stackoverflow.com/questions/450865/what-is-the-equivalent-to-posix-popen-in-the-win32-api/450950#450950

Rich.

-- 
Richard Jones, Emerging Technologies, Red Hat  http://et.redhat.com/~rjones
New in Fedora 11: Fedora Windows cross-compiler. Compile Windows
programs, test, and build Windows installers. Over 70 libraries supprt'd
http://fedoraproject.org/wiki/MinGW http://www.annexia.org/fedora_mingw



More information about the mingw mailing list