views:

243

answers:

2

I am using Java Runtime to run commands, including certain CVS commands.
I use:

process = runtime.exec ("cmd /C cvs...");

format for running the Process in Java
I need to have the option of stopping it. For this I use the Java Process destroy method

process.destroy();


However only the cmd is stopped not the cvs process. It continues to run as a separate process without the cmd process as the parent.
There are many references to this on the internet, but I haven't found any satisfactory solution. Thanks

+2  A: 

This is a problem with the windows cmd shell. Why do you use it? Can't you do exec("cvs ...") instead?

Arne Burmeister
Exactly. Any reason why you must use cmd /C?
Seun Osewa
Thanks for the replies.I use cmd /C because otherwise I will not be able to run Windows commands from Java(like dir etc). However what you said, I tried for CVS and it does work fine!! So that does solve one part of my problem.But I did try it for another program gmake.exe, which spawns other processes while its running, and when I use destroy on it the subprocesses it spawns do not stop. So the problem of stopping a process tree still remains..
ages04
A: 

It may be possible using Runtime.exec to get the PID of the process you have run. And with that you might be able to shut down the process tree.

You would however need 2 other programs to find the PID and to terminate the process tree.

jex