Win32 Redirect stdOut stdErr in same process

Igor Pechtchanski
Thu Mar 11 20:17:00 GMT 2004

On Thu, 11 Mar 2004, Valerio Ferrucci wrote:

> Errata corrige: in my previous mail I wrote stdIn where I wanted to mean stdOut
> Hi,
> I hope that someone on the list can help me about this or point me to
> some docs or example.
> My Win32 application calls an external library that writes to stdOut
> and stdErr. I want to capture (redirect) these outputs (in order to
> send them back to the user via http). Note that I can't spawn another
> process because the library must run in the same process context of
> the caller.
> On Unix my code is very simple:
> int     fdOut[2]={-1, -1};
> pipe(fdOut)
> dup2(fdOut[1], STDOUT_FILENO)
> ... call the library
> fcntl(fdOut[0], F_SETFL, fileFlags | O_NONBLOCK)
> ... read from fdOut[0]
> Any idea on how to do this using Win32 API?
> Any working example?
> Thanks for help


The above Unix code should work OOTB on Cygwin.  Just compile it and run
it.  Note that you'll require at least cygwin1.dll to run the application.

If you're asking how to do this *without* Cygwin, then this is off-topic
for this list, and you should ask somewhere else (e.g., on a Win32 list or
forum).  Just to give you a hint, the code above may still work OOTB with
MinGW (see <> for project and contact information).
      |\      _,,,---,,_
ZZZzz /,`.-'`'    -.  ;-;;,_
     |,4-  ) )-,_. ,\ (  `'-'		Igor Pechtchanski, Ph.D.
    '---''(_/--'  `-'\_) fL	a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!

"I have since come to realize that being between your mentor and his route
to the bathroom is a major career booster."  -- Patrick Naughton

Unsubscribe info:
Problem reports:

More information about the Cygwin mailing list