如何销毁java中的流程构建器生成的流程

时间:2016-04-18 11:13:55

标签: java terminal processbuilder destroy

我有processbuilder运行.sh script。它打开了一个终端。我想稍后破坏这个终端。我试过process.destroy(),但它没有完成这项工作。

代码:

Process p = new ProcessBuilder("/usr/bin/gnome-terminal", "-e", "/home/omar/ros_ws/./baxter2.sh").start();  
try {  
    Thread.sleep(10000); // wait for one second  
} catch (InterruptedException ex) {   
    Thread.currentThread().interrupt();  
} 
p.destroy();  

1 个答案:

答案 0 :(得分:0)

try  

{

Process[] proc = new Process[2];

proc[0] = new ProcessBuilder("calc.exe").start();

proc[1] = new ProcessBuilder("notepad.exe").start();


try {
    Thread.sleep(3000);
} catch (InterruptedException ex) {
}

proc[0].destroy();
proc[1].destroy();

}

catch (IOException ioe)
 { 
ioe.printStackTrace();
}