Redirecting Python stdout ,stderr and stdin

J

Jan Knop

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 ?
 
A

Alexander Schmolck

Jan Knop said:
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
 
S

Serge Orlov

Alexander Schmolck said:
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
 
A

Alexander Schmolck

Serge Orlov said:
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
 
J

Jan knob

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top