Results 1 to 4 of 4
  1. #1
    scamiolo is offline Member
    Join Date
    Jul 2011
    Posts
    2
    Rep Power
    0

    Default Monitoring processes

    Hi there

    I am using a JAVA GUI in order to launch some C scripts. Such scripts take quite long time and I would like to implement a progress bar n the GUI that follows the C script progress. Just to put it simple I am using the following code to launch the process within the java program:

    Java Code:
                 Process p=Runtime.getRuntime().exec("stampaCiao");
    
                BufferedReader reader = new BufferedReader( new InputStreamReader(p.getInputStream()) );
    
                String line = null;
                while( (line = reader.readLine()) != null )
                jTextArea1.setText(String.valueOf(line));
    The program stampaCiao just print numbers from 1 to 10 sequentially (one every second). I would like to have in my jTextArea1 the number as long as they are generated. However the jTextArea1 is updated only when the process p ends completely. Is there a way to catch the output of stampaCiao in real time when is is generated instead of the end of the process?

    thanks for your help!

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default

    If this code is in your Swing thread (ie the EDT) rather than a SwingWorker then it cannot update the test area until this code finishes, since the EDT is what does that updating. So launch this in a SwingWorker or similar.

  3. #3
    scamiolo is offline Member
    Join Date
    Jul 2011
    Posts
    2
    Rep Power
    0

    Default

    Hi there,

    thanks a lot for your reply. I am having a look at the SwingWorker class but it looks a bit complicated for my Java knowledges. Can you provide me with clean and simple example to achieve what you advised me in the last post please (or some link)?
    thanks!

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

Similar Threads

  1. how to run parallel processes ?
    By mapred.learn in forum New To Java
    Replies: 2
    Last Post: 03-02-2011, 12:45 AM
  2. Too many java.exe processes due to netbeans
    By abhishek.jain in forum NetBeans
    Replies: 7
    Last Post: 12-29-2009, 01:52 PM
  3. Replies: 22
    Last Post: 09-06-2009, 05:21 PM
  4. Halt applet processes.
    By barusk in forum Java Applets
    Replies: 1
    Last Post: 04-06-2009, 05:11 PM
  5. netbeans processes don´t die
    By karlen in forum NetBeans
    Replies: 0
    Last Post: 06-11-2007, 09:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •