473,686 Members | 2,149 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Redirecting Python stdout ,stderr and stdin

Hello

I am writing a Windows application where I need to redirect stdin,
stdout and stderr from Python. to my application
Is it a simple way of do it ?
Has anyone done it using Winsock ?


Jul 18 '05 #1
4 38722
Jan Knop <no****@nospam. yes> writes:
Hello

I am writing a Windows application where I need to redirect stdin,
stdout and stderr from Python. to my application
Is it a simple way of do it ?


import sys
sys.stdin, sys.stderr, sys.stdout = map(open, 'in.txt err.txt out.txt'.split( ),
'r w w'.split())
'as
Jul 18 '05 #2

"Alexander Schmolck" <a.********@gmx .net> wrote in message news:yf******** *****@black132. ex.ac.uk...
Jan Knop <no****@nospam. yes> writes:
Hello

I am writing a Windows application where I need to redirect stdin,
stdout and stderr from Python. to my application
Is it a simple way of do it ?


import sys
sys.stdin, sys.stderr, sys.stdout = map(open, 'in.txt err.txt out.txt'.split( ),
'r w w'.split())


That is why map should be deprecated asap ;)

sys.stdin = open("in.txt")
sys.stdout = open("out.txt", "w")
sys.stderr = open("err.txt", "w")

-- Serge
Jul 18 '05 #3
"Serge Orlov" <so********@pob ox.ru> writes:
"Alexander Schmolck" <a.********@gmx .net> wrote in message news:yf******** *****@black132. ex.ac.uk...
Jan Knop <no****@nospam. yes> writes:
Hello

I am writing a Windows application where I need to redirect stdin,
stdout and stderr from Python. to my application
Is it a simple way of do it ?


import sys
sys.stdin, sys.stderr, sys.stdout = map(open, 'in.txt err.txt out.txt'.split( ),
'r w w'.split())


That is why map should be deprecated asap ;)

sys.stdin = open("in.txt")
sys.stdout = open("out.txt", "w")
sys.stderr = open("err.txt", "w")


The obfuscation in the above example was intended not to immediately overwhelm
the OP (who expected having to use some winsock thingy) with simplicitly and
clarity, but now you've spoilt it.
'as
Jul 18 '05 #4
On 24 Nov 2003 02:02:50 +0000, Alexander Schmolck <a.********@gmx .net>
wrote:
"Serge Orlov" <so********@pob ox.ru> writes:
"Alexander Schmolck" <a.********@gmx .net> wrote in message news:yf******** *****@black132. ex.ac.uk...
> Jan Knop <no****@nospam. yes> writes:
>
> > Hello
> >
> > I am writing a Windows application where I need to redirect stdin,
> > stdout and stderr from Python. to my application
> > Is it a simple way of do it ?
>
> import sys
> sys.stdin, sys.stderr, sys.stdout = map(open, 'in.txt err.txt out.txt'.split( ),
> 'r w w'.split())


That is why map should be deprecated asap ;)

sys.stdin = open("in.txt")
sys.stdout = open("out.txt", "w")
sys.stderr = open("err.txt", "w")


The obfuscation in the above example was intended not to immediately overwhelm
the OP (who expected having to use some winsock thingy) with simplicitly and
clarity, but now you've spoilt it.
'as


Hi

Actually that what I wat in the end is a method for subsclassing the
python stdio's into my application window. This means that Python runs
in background with all threes stdio streams redirected .
This is I believe somehow done in the Komodo program from
ActiveState
As far as I have found out You need to define a Input and output
class and imlement Read Readline , Write and WriteLine method in
these classes.
Otherwise it will be necessary to somehow capture the Stdin stdout
streams from python console and redirect them .

with regards
Jan

Jul 18 '05 #5

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

Similar topics

6
2516
by: calmar | last post by:
Hi all, I would like to use python for a replacement for some binutils. I would like to be able to pipe things into python. Actually I would not like writing a 'script' to handle the input, but write the python commands right onto the command line. It would be possible to use here-documents (for having the correct identation during e.g while loops) for writing python code on the fly, but then how and where to get the pipe output:
3
3756
by: David Douard | last post by:
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
2
4544
by: Xah Lee | last post by:
Python Doc Problem Example: os.system Xah Lee, 2005-09 today i'm trying to use Python to call shell commands. e.g. in Perl something like output=qx(ls) in Python i quickly located the the function due to its
0
1775
by: todddeluca | last post by:
I am posting code for calling almost any python function from php, because it seems generally useful. Please feel free to suggest improvements or tell me this has already been done better somewhere else, etc. My limited searching turned up nothing. I work in a heterogeneous environment with php web pages and python modules/scripts. This code requires no no creation of an ad hoc command line interface to the python module and/or ad hoc...
9
1761
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.
2
2687
by: Pierre Rouleau | last post by:
Hi all, I have a consistent test case where os.popen3() hangs in Windows. The system hangs when retrieving the lines from the child process stdout. I know there were several reports related to os.popen3() hanging under Windows in this group before. I stumbled on a case where a piece of code works in some occasions and hangs consistently given different data. It performs exactly the same on 3 different computers running Windows:
4
2293
by: lovecreatesbea... | last post by:
For example, in Bourne Shell both stdout and stderr can be re-directed to /dev/null, $ ./a.out 2>&1 /dev/null then is there any difference still?
1
6693
by: Lincoln Yeoh | last post by:
Hi, I've just started to learn python (I've been using perl for some years). How do I redirect ALL stderr stuff to syslog, even stderr from external programs that don't explicitly change their own stderr? Say I have a program called foo: #!/usr/bin/python
0
1992
by: Gabriel Genellina | last post by:
En Thu, 25 Sep 2008 09:49:31 -0300, Almar Klein <almar.klein@gmail.com> escribió: Use subprocess.PIPE Usually the tricky part is to figure out exactly whether there is more input or not. With Python it's easy, use the ps1 prompt. --- begin --- import sys
0
8586
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9057
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...
1
8772
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
8780
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...
0
7603
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6442
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
5800
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();...
1
2953
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2208
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.