• Post Reply Bookmark Topic Watch Topic
  • New Topic

Equivalent for "CTRL+C" for process made in Java

 
Daniel Lawton
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am running pentaho jobs from command line in Java.
The pentaho job runs fine, and I am able to see the output of the command line inside a JTextArea which updates in real time.#

I now would like a "Stop" button, which does the equivalent of "CTRL+C" in the windows command prompt.

I was trying to use .destroy for the process inside a button, however this doesn't seem to work.
process is a public variable by the way.

Code:
 
Daniel Lawton
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have now tried implementing a shutdownhook when the 'somethingButton' is pressed. Here is what I've tried.

 
Stephan van Hulst
Bartender
Posts: 6583
84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could try process.destroyForcibly().waitFor().

Why are you catching the IOException at the beginning? I'm assuming that you only want to interact with the process if you've started it successfully.

I'm assuming this is a constructor, because you're adding an action listener to a button in this code. If it is, it's inappropriate to spawn a thread here. In fact, you shouldn't be using a thread at all, you should be using a SwingWorker.

You can use a lambda to add your action listener.
 
Norm Radder
Bartender
Posts: 1526
14
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!