I am using p = Runtime.getRuntime().exec("myScript.sh"); as part of a actionPerformed(ActionEvent evt) of button A's addActionListener(new ActionListener().
I would like to have a way to terminate the process. I tried to create another button (button B) which calls p.destroy(). However, it looks like after clicking on button A, it launches the process and only until the process finishes, can I click on other buttons (including the closing button on the top right) on the GUI. So I can't terminate the process in the middle.
Is there any way I can terminate the process? Or is there any way I can click other buttons while the process initiated by button A is still running?
I commented out the p.waitFor(); I still cannot click other buttons after clicking btnRun
private Process p;
btnRun.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
String s;
try {
p = Runtime.getRuntime().exec(command);
BufferedReader br = new BufferedReader(
new InputStreamReader(p.getInputStream()));
while ((s = br.readLine()) != null)
System.out.println(s);
//p.waitFor();
//System.out.println ("exit: " + p.exitValue());
//p.destroy();
} catch (Exception e) {}
}
});
btnTerminate.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
p.destroy();
}
});