Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

redirect system.out ??  RSS feed

 
steve dowdall
Ranch Hand
Posts: 36
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I cant seem to do this.
I have a text jTextArea and a jButton. When the user clicks the button, I want to have the system.out show up in the jTextArea INSTEAD of an output window.
Can someone help me please?
Steve
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll have a quick attempt:
You can use the call System.setOut(PrintStream out) to alter where data sent to the standard output stream is sent.
now its a case of creating the stream you want (probably a Reader cos it's text)
As to how you now redirect it to a jTextArea, dunno, I don't do the Swing thing
If you can plug the stream into the TextArea it's fine, otherwise you might need a separate Thread monitoring the stream and appending to the TextArea...

Dave.
 
Ryan Langley
Ranch Hand
Posts: 46
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I don't think it's necessary to redirect System.out at all in your program.. Your question does not outline where the input to the textarea is coming from, so it makes it more difficult to get a picture of what is going on. All you need to do is use the append() method on your JTextArea object to add text to it.. System.out should not be used at all for putting text in a JTextArea. I would offer more help, but I don't know enough about your code to help.. Anyways, hope this helps you. Good luck!
Cheers,
RL
[This message has been edited by Ryan Langley (edited May 24, 2001).]
 
steve dowdall
Ranch Hand
Posts: 36
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all,
I know it does not make a whole lot of sense, but this is what I am trying to do:
I have a form with buttons that launch other apps. I wanted to try and capture the system.out.println stuff from these apps and throw it into a scrollable text area. That way I can view the output from one place as I run the apps.
Any more thoughts appreciated.
Steve
 
Krum Kubratov
Greenhorn
Posts: 1
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am also very interested in how the problem can be solved. If you know please, mail
I thought of a solution of the kind:
tdout = new PrintStream (new FileOutputStream("Redirect.out"));
 
David Demner
Greenhorn
Posts: 5
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The way I have found to do it is something like this:

[This message has been edited by David Demner (edited October 10, 2001).]
 
Joris Verreijt
Greenhorn
Posts: 1
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

The key part in Davids solution is overwriting the printnl(String) method in a subclass of the PrintStream class. This approach however does only work fine as long as the println(String) method is used for sending messages to System.out. In order to make this work for all methods of the PrintStream class, all print and println methods should be overwritten.

I found that an easy way to overcome this problem is by subclassing the OutputStream class and pass an instance of this class to a PrintStream class.



Note that the PrintSteam is constructed with a boolean that is set to true. According to the Java API doc, this option should make sure that the PrintStream flushes at all moments that you want it to flush. With the little testing that I did, it seemed to be working fine.

Joris
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!