473,883 Members | 1,602 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_UNI X, SOCK_STREAM)
s.connect(...)
os.dup2(sys.__s tdout__.fileno( ), s.fileno())
very_intensive_ function(many_p arameters)
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 3765
David,

Googling comp.lang.pytho n /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_UNI X, SOCK_STREAM)
s.connect(...)
os.dup2(sys.__s tdout__.fileno( ), s.fileno())
very_intensive_ function(many_p arameters)
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.Creat ePipe). 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.pytho n /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_UNI X, SOCK_STREAM)
s.connect(...)
os.dup2(sys.__s tdout__.fileno( ), s.fileno())
very_intensive_ function(many_p arameters)
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.Creat ePipe). 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
12720
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 script to a file (including that which is printed by the spawned programs) via the redirect (">") function on a Win2K Command Prompt. In the captured output however, the output from the os.system() calls ALWAYS comes before the output from the...
0
2593
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) command line utility as redirecting its input and output so I can interact with this one. This utility is similar to ftp under a win32 console. It proposes its own prompt after launching it.
3
3443
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
4590
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 redirection is useless in that case) and I would like to do it without reverting to C-run time library P/Invoke calls. Any ideas how to do that?
6
4177
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 input and output so I can interact with this one. This utility is similar to ftp under a win32 console. It proposes its own prompt after launching it. What I want to do is:
9
1773
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 that could import sys afterwards - so I don't want to make the change in the sys module.
8
5797
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 technically create an executable that calls the function and then using a command prompt call the exexutable using the > output.txt redirector but I would prefer to do everything within the application itself. Is there a way for force an output...
1
2599
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 file. My issue is that I try to read from the stdout stream and never get anything only if the program has exited. Is there a way of reading the redirected stdout from a DOS program in say real time? I have tried the async (BeginOutputReadLine) and...
0
1835
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 did not require redirection due to the fact that every X11 application can have an STDOUT associated with it. I then proceeded to take interest in making my code portable and looked at compiling it on windows, however Win32 GUI applications are...
0
9779
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11114
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10730
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10835
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10407
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7960
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7114
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5982
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3230
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.