Redirecting stdout/err under win32 platform

yaipa yaipa at yahoo.com
Mon Jan 31 01:06:36 EST 2005


David,

Googling comp.lang.python /w this string "stderr win32" yielded 109
results.
So I think if you poke around a bit you will find your answer in the
archives.

Sorry for no direct help tonight...

Cheers,

--Alan
David Douard wrote:
> Hi everybody,
>
> let me explain by problem:
> I am working on an application which consists in a C++ dll (numeric
> computations) and a Python IHM (Python/Tk), which must run under
Linux and
> win32. My problem is the C++ lib does write stuffs on its stdout, and
I
> would like to print those messages in a Tk frame. When I run the
> computation, it has it's own thread.
>
> So my question is : how van I redirect the dll's stdout to something
I can
> retrieve in Python (pipe, socket,...)?
>
> I can do it easily under Linux. I made tests with a socket which just
works
> fine. In the threaded function (that will do the heavy computation),
I
> write:
>
> import os, sys
> from socket import *
> s=socket(AF_UNIX, SOCK_STREAM)
> s.connect(...)
> os.dup2(sys.__stdout__.fileno(), s.fileno())
> very_intensive_function(many_parameters)
> s.close()
>
> That's OK under Linux, but does not work under win32 (even if I use
an INET
> localhost socket), cause I cannot do the os.dup2 trick (Windows does
not
> want to consider a socket as a file! What a shity system!).
>
> So my question is : is there a simple solution ? I have tested
different
> solutions. I am trying hacks with pipes created with the win32api.
But I
> have not yet managed this simple operation.
>
> Note that I have no access to the dll source code, so I cannot modify
it so
> it uses a named pipe (for example) as message output pipe instead os
> stdout...
> 
> Thanks,
> David




More information about the Python-list mailing list