This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

redirecting output to a swing component  RSS feed

 
Chris Dancy
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just wondering of an easy way to redirect the output of say an external program to a swing component. How netbeans or eclipse will redirect the console output to a TextArea, which is what I want but using ruby. Any ideas?

Sincerely,
Chris Dancy
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the output is from your own application, you can redirect System.out by calling System.setOut. For external programs you are calling from your application you can read the input and error InputStreams, and write the contents to an OutputStream.

Now that we've explained that, you still need an OutputStream or Writer that writes to your (J)TextArea. If you don't want to redirect your own System.out, I'd prefer a Writer though, since it can handle text better. You can always wrap an InputStream into an InputStreamReader for the copying.

Here's how your writer could look like:
 
Chris Dancy
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey sorry this is so late in getting back to you I've been away from the internet for a week or so. That was not exactly what I was looking for however playing around with that code allowed me to get what I wanted. So Thank you.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!