Mailing List Archive

To redirect stdin,out
Hello,everyone.

I want to redirect standard input and output
to my C++ stream object and
use something like PyRun_InteractiveLoop().

It seems we can redirect standard output by ...
(quoted from http://www.python.org/doc/FAQ.html)

class StdoutCatcher:
def __init__(self):
self.data = ''
def write(self, stuff):
self.data = self.data +stuff
ToCppObject(self.data) #pass data to
C++ object

import sys
sys.stdout = StdoutCatcher()
print 'foo'

I am at a loss how to redirect standard input.
If you know any solutions,Please Help!


Thanks for reading.

Thooney Millennier
To redirect stdin,out [ In reply to ]
Thooney Millennier <thooney@pk.highway.ne.jp> writes:

>
> import sys
> sys.stdout = StdoutCatcher()
> print 'foo'
>
> I am at a loss how to redirect standard input.
> If you know any solutions,Please Help!

Well, I tried the obvious analog of this code snippet:

import sys
sys.stdin = open("one_of_my_files.txt")
print raw_input()

And it seemded to work fine. Am I missing something?

Greetings,

Stephan