473,386 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Redirecting stdout/err under win32 platform

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
Jul 18 '05 #1
3 3724
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


Jul 18 '05 #2
Alan,

I did search Google for this problem (not enough, thou).
In fact, I found some kind of solution (by myself, not that much on Google),
but it is not really satisfactory.

I have used win32 pipes to do so (win32api.CreatePipe). I can redirect
stdout/stderr to it from my python code (even redirecting the stdout/stderr
from my C lib).
But I still have a problem with this solution (well, 2):
- it is *much* more complicated than any solution available on Unix like
systems (not really a problem, but),
- it not synchronous at all. And I'd like it to be so (or almost so).

David

yaipa wrote:
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


Jul 18 '05 #3
David Douard a écrit :
Alan,

I did search Google for this problem (not enough, thou).
In fact, I found some kind of solution (by myself, not that much on Google),
but it is not really satisfactory.

I have used win32 pipes to do so (win32api.CreatePipe). I can redirect
stdout/stderr to it from my python code (even redirecting the stdout/stderr
from my C lib).
But I still have a problem with this solution (well, 2):
- it is *much* more complicated than any solution available on Unix like
systems (not really a problem, but),
- it not synchronous at all. And I'd like it to be so (or almost so).

David


AFAIK, there is no working bidirectionnal pipes on Windows ! The
functions exists in order for them to claim being POSIX, but they're not
working properly. Under Windows environment, I suppose you have to find
your way using their buggy pipes (and by no means their "POSIX" pipes)
or you have to use another inter-process communication protocol (DDE,
COM, ...).

Pierre
Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Birch | last post by:
I have a python script that uses the print function throughout, and as well uses calls to os.system() to spawn DOS commandline executables. My issue is that I redirect all of the output from this...
0
by: Christophe HELFER | last post by:
hi, I have some problem with redirecting input and output from a process. I can only use VB language (sorry...) Situation: I have to use the Cisco Network Registrar (DNS And DHCP server) ...
3
by: Laszlo Zsolt Nagy | last post by:
Hello, I have this code: s = smtplib.SMTP() s.set_debuglevel(1) s.connect(host=smtp_host) s.set_debuglevel(0) log("Connected, sending e-mail") sys.stdout.flush()
2
by: Jacek | last post by:
Hello! My application has to use external native library writing to stdout and stdin. My goal is to redirect output within running process (no chance to do that in child process - Process class...
6
by: Christophe Helfer | last post by:
hi, I have some problem with redirecting input and output from a process. Situation: I have to use the Cisco Network Registrar (DNS And DHCP server) command line utility as redirecting its...
9
by: Fuzzyman | last post by:
Hello, I'm trying to redirect standard out in a single namespace. I can replace sys.stdout with a custom object - but that affects all namespaces. There will be code running simultaneously...
8
by: Morpheus | last post by:
I am trying to test a function that outputs text to the standard output, presumably using a cout call. I do not have access to the source, but need to test the output. Is this possible? I can...
1
by: pp4175 | last post by:
Hello Everyone, I am currently working on writing a GUI wrapper for a Menu driven DOS Program. What I was looking on doing is redirecting stdout/stdin to a stream and read/write similar to a...
0
by: Tom Gaudasinski | last post by:
Greetings, I'm trying to redirect python's stdout to another location. The reason for this is that I'm embedding python in an application. Now, originally my code was developed for Linux and that...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.