Determine when a process has ended?

Discussion in 'Java' started by news.amnet.net.au, Feb 20, 2004.

  1. Hi

    I am running a process with the runtime command:

    Process p = Runtime.getRuntime ().exec (command);

    It is very important to me that I know when the process has completed, as
    then immediately afterwards I have to do somethign else.
    I have tried to get the exitValue() i.e.

    int complete = p.exitValue();

    But I get an exitvalue of 0 back even before the process completes.
    Is there a foolproof way to find out when a process has completed?

    My full code of the java program I call from a jsp to start the process is
    like this:

    package geoinformex.process;
    import java.io.*;
    import java.net.*;
    import java.util.*;

    public class RunProcess {

    Process p;

    public Process RunProcess (String command , boolean wait) {

    try
    {
    p = Runtime.getRuntime ().exec (command);
    }
    catch ( IOException e )
    {
    return null;
    }
    if ( wait )
    {
    try
    {
    p.waitFor();
    }
    catch ( InterruptedException e )
    {
    Thread.currentThread().interrupt();
    }
    }
    return p;
    }
    }

    Then in my jsp I do this:

    String command = "some command here";
    boolean wait = false;

    RunProcess proc = new RunProcess();
    proc.RunProcess(command,wait);

    int exitvalue = proc.exitValue();

    But, as I said, this exitValue() immediately returns 0, even before the
    process completes.

    Any help with determining when a process has completed will be very welcome.

    Thanks very much

    Hugo
     
    news.amnet.net.au, Feb 20, 2004
    #1
    1. Advertising

  2. news.amnet.net.au

    David Roden Guest

    news.amnet.net.au wrote:

    > String command = "some command here";
    > boolean wait = false;


    If you want to wait for the end of the process, why don't you say so?
     
    David Roden, Feb 20, 2004
    #2
    1. Advertising

  3. news.amnet.net.au

    Chris Smith Guest

    news.amnet.net.au wrote:
    > I am running a process with the runtime command:
    >
    > Process p = Runtime.getRuntime ().exec (command);
    >
    > It is very important to me that I know when the process has completed, as
    > then immediately afterwards I have to do somethign else.
    > I have tried to get the exitValue() i.e.
    >
    > int complete = p.exitValue();
    >
    > But I get an exitvalue of 0 back even before the process completes.
    > Is there a foolproof way to find out when a process has completed?


    You'll have to use the waitFor method. If you need to find this out
    without waiting for the process to complete, you may need to create a
    new Thread to wait for the process to complete, and then set a boolean
    flag somewhere and Object.notify() or some such thing.

    --
    www.designacourse.com
    The Easiest Way to Train Anyone... Anywhere.

    Chris Smith - Lead Software Developer/Technical Trainer
    MindIQ Corporation
     
    Chris Smith, Feb 20, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. tshad

    Session has ended message

    tshad, Mar 4, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    942
    Jc Morin
    Mar 5, 2005
  2. mantarraya
    Replies:
    2
    Views:
    1,371
    Andrew Thompson
    Aug 5, 2004
  3. MikeL

    Ended debugging, program still ran

    MikeL, Jun 9, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    376
    ChrisG
    Jun 9, 2006
  4. Jan C. Faerber
    Replies:
    0
    Views:
    527
    Jan C. Faerber
    Nov 14, 2009
  5. Lukasz Muziol
    Replies:
    5
    Views:
    110
    Lukasz Muziol
    Aug 10, 2006
Loading...

Share This Page