How to Rediret STDOUT

From: Werner F. Bruhin [mailto:werner.bruhin@free.fr]

>How can I redirect stdout to
>wxTextCtrl ?
>
>
I redirect stdout and stderr to a file:
        self.stdoutlog = file(r'stdoutlog.txt', 'a+')
        self.stderrlog = file(r'stderrlog.txt', 'a+')
        sys.stdout = self.stdoutlog
        sys.stderr = self.stderrlog

Then you can write them to your multiline textctrl.

        self.tctrlstdout.WriteText(self.stdoutlog.read())
        self.trctrlstderrlog.WriteText(self.stderrlog.read())

You don't need to write to a file. You can directly add a write() method to
a wxTextCtrl instance, via inheritence, or add it directly to the instance,
then do:

sys.stdout = myTextCtrlOut
sys.stderr = myTextCtrlErr

assuming you have one for stdout and one for stderr. BTW, this has been
discussed many times on this list so also look at the archives for
alternatives or more details, especially as posted by Robin Dunn himself.

HTH,
Oliver