t**i 发帖数: 9 | 1 I have a process p = Runtime.getRuntime().exec("some programe). After a
timeout(say t), I need to stop this process if it haven't finish running.
What's the nice way to do that?
Thanks! |
g*******e 发帖数: 14 | 2 check javadoc. I believe it must be there.
【在 t**i 的大作中提到】 : I have a process p = Runtime.getRuntime().exec("some programe). After a : timeout(say t), I need to stop this process if it haven't finish running. : What's the nice way to do that? : Thanks!
|
f*****g 发帖数: 31 | 3
No way from Java. But you can call native function/command to halt
your process.
【在 t**i 的大作中提到】 : I have a process p = Runtime.getRuntime().exec("some programe). After a : timeout(say t), I need to stop this process if it haven't finish running. : What's the nice way to do that? : Thanks!
|
t**i 发帖数: 9 | 4 Thanks!
Now I found out I can't tell if the process's status after t. If I do
p.exitValue(), it throws IllegalThreadException. If I do p.waitFor(), it
ignores my timing while loop. What I did in my code is:
while (System.currentTimeMillis() - startTime < t)
{
if (p.waitFor() == 0)
break;
}
Could you advise?
Thanks!
【在 f*****g 的大作中提到】 : : No way from Java. But you can call native function/command to halt : your process.
|
g*******e 发帖数: 14 | 5 p.destroy()
【在 t**i 的大作中提到】 : Thanks! : Now I found out I can't tell if the process's status after t. If I do : p.exitValue(), it throws IllegalThreadException. If I do p.waitFor(), it : ignores my timing while loop. What I did in my code is: : while (System.currentTimeMillis() - startTime < t) : { : if (p.waitFor() == 0) : break; : } : Could you advise?
|