How to get the status of the runtime process in java..?

J

janak

Hi,
I am trying to execute a System command located at remote machine.So i
use Rmi concept for this purpose.

The model source code is
try
{
Runtime r = Runtime.getRuntime();
Process p = r.exec("System command");
int e = p.waitFor();
System.out.println("The process value :" + e);
}

catch
{
....}

I got succeed in executing the file.here waitFor() method will return a
value 0 (if the process executed successfully) or 1 (if the process
execution fails)But the problem i faced is i cant able to get the
status of that execution whether it is running or get terminates. The
waitFor() method work successfully on the terminal(or command window in
windows)when i terminate the process by using ^C but when i tried this
in JSP i cant able to terminate the process. I tried to use the
exitValue() method but i cant. How to monitor the runtime process on
remote machine. I am using Linux and Netbeans IDE.

Can anyone give solution to this.....


S.Janakiraman
 
T

Thomas Fritsch

janak said:
The model source code is
try
{
Runtime r = Runtime.getRuntime();
Process p = r.exec("System command");
int e = p.waitFor();
System.out.println("The process value :" + e);
}

catch
{
...}

I got succeed in executing the file.here waitFor() method will return a
value 0 (if the process executed successfully) or 1 (if the process
execution fails)But the problem i faced is i cant able to get the
status of that execution whether it is running or get terminates. The
waitFor() method work successfully on the terminal(or command window in
windows)when i terminate the process by using ^C but when i tried this
in JSP i cant able to terminate the process. I tried to use the
exitValue() method but i cant. How to monitor the runtime process on
remote machine. I am using Linux and Netbeans IDE.

Can anyone give solution to this.....
According to the API doc at
<http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Process.html#exitValue()>
you could do

public static boolean isRunning(Process process) {
try {
process.exitValue();
return false;
} catch(IllegalThreadStateException e) {
return true;
}
}
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,783
Latest member
RickeyDort

Latest Threads

Top