N
news.amnet.net.au
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
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