By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,467 Members | 1,308 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,467 IT Pros & Developers. It's quick & easy.

redirect of standard output of jython to JTextArea

P: n/a
Hello

I want to redirect output of jython's functions print and println to
JTextArea component. Is it possible ?

I tried this (swingConsole.textArea is instance):

In my class

self.printStream= MyPrintStream(System.out)
System.setOut(self.printStream)

----------------------------------------------------
class MyPrintStream (PrintStream):

def println (str):
swingConsole.textArea.append(str)

def print (str):
swingConsole.textArea.append(str)
Output is still directed to standard output.
Thanks for help,
Jan
Jul 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
problem solved.

in class:

sys.stdout = StdOutRedirector(self)
class StdOutRedirector:
def __init__(self, console):
self.console = console

def write(self, data):
#print >> sys.stderr, ">>%s<<" % data
if data != '\n':
# This is a sucky hack. Fix printResult
self.console.textArea.append(data)

Jan

Jan Gregor wrote:
Hello

I want to redirect output of jython's functions print and println to
JTextArea component. Is it possible ?

I tried this (swingConsole.textArea is instance):

In my class

self.printStream= MyPrintStream(System.out)
System.setOut(self.printStream)

----------------------------------------------------
class MyPrintStream (PrintStream):

def println (str):
swingConsole.textArea.append(str)

def print (str):
swingConsole.textArea.append(str)
Output is still directed to standard output.
Thanks for help,
Jan

Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.