How do i terminate a process tree from Java?

前端 未结 5 1295
离开以前
离开以前 2021-02-05 15:26

i am using Runtime.getRuntime().exec() command in Java to start a batch file which in turn starts another process for windows platform.

javaw.exe(Process1)
 |___         


        
5条回答
  •  耶瑟儿~
    2021-02-05 16:07

    With java 9, killing the main process kills the whole process tree. You could do something like this:

    Process ptree = Runtime.getRuntime().exec("cmd.exe","/c","xyz.bat");
    // wait logic
    ptree.destroy();
    

    Please take a look at this blog and check out the Deal with Process Trees example.

提交回复
热议问题