I want to redirect the output of a command executed by ProcessBuilder to the jTextArea component at the time of its execution rather than at its end of execution.
If I'm right, your are looking for redirecting the standard output stream to a text area. You'll find plenty examples around. The basic idea is to use a PipedOutpoutStream and create a thread to listen to it. In fact, you should intercept both the out and err streams.
In the attached example, I used a JTextPane instead of a JTextArea in order to use another color (red) for error messages. If this is not needed, you can just use a JTextArea and get rid of the "color" related stuff.
Thank you for your response Jourquin. What exactly that I'm looking for, is how to redirect output stream delivered by a process when executing a given command to a JTextArea . In others words, I want to get the output stream of an application that will be executed via processbuilder in a JTextArea but at the time of its execution not at the end of execution.
Yes, I undestand. Therefore, you need to capture the input and error streams from the process. See the attached file for a working example. You'll also need the Console.java code attached to my previous answer.
Your code works fine, I have test it with netbeans IDE. But when I tried to replace windowadapter class with Jframe class in console.java, the code doesnt seem to work, I got an error message ( Class is not abstract ....).
If you use a JFrame, you indeed need to implement some additional methods inherited from (the abstract) WindowListener. You also need to remove the declared JFrame "frame" variable that was present in Console.java.
Note there is a typo in the source of Console2.java: ".windowOpened(WindowEvent)" on line 101 which was probably introduced by a not wanted paste while I was preparing this for you :-( Sorry