469,343 Members | 5,388 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,343 developers. It's quick & easy.

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 38309
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********@pobox.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********@pobox.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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by David Douard | last post: by
2 posts views Thread by Xah Lee | last post: by
reply views Thread by todddeluca | last post: by
9 posts views Thread by Fuzzyman | last post: by
4 posts views Thread by lovecreatesbea... | last post: by
1 post views Thread by Lincoln Yeoh | last post: by
reply views Thread by Gabriel Genellina | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.