Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Redirect output from stderr, stdout to a JTextArea

 
Konstantinos Vasileiou
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have implemented a program that invokes some Linux commands to complete a number of tasks. My problem is that I want to add a GUI to the application, so I need to somehow redirect the output of the commands from the error and the out streams to a graphical components, such as a JTextArea.... However, I am not sure how to do it. The code I currently have looks like this:


 
Rob Camick
Ranch Hand
Posts: 2616
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The [Message Console might be what you are looking for.
 
Ramses Butarbutar
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Konstantinos ,

If i'm not mistaken, you wanna get your error (your stack trace info???) and put in some components such a JTextArea ?

Just define the exception, catch it, put it in stringwriter and parse into string.
After that you can easily throw it into your JTextArea.



Have a nice try..
 
Rob Spoor
Sheriff
Pie
Posts: 20667
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Camick wrote:The [Message Console might be what you are looking for.

It would be great if it was the stderr and stdout of the current application that should be great. In this case, it's the stderr and stdout from a separate process.

Konstantinos, first of all, please read this. You'll find it very useful.
In that article, the StreamGobbler code on page 4 is almost what you want. However, instead of printing, you want to add it:
Apart from appending only the exception's String form, you can print the stack trace to the text area as well, using my patented ( ) TextAreaWriter:
 
Konstantinos Vasileiou
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you - very helpful and detailed reply!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic