1

I am trying to write a chatbot. I am still in my startings, but I do have one question.

Process proc = Runtime.getRuntime().exec("notepad.exe");

This actually makes it impossible to quit my program, unless I quit the notepad. Is it possible to quit the Java program before this notepad has ended?

Ken White
  • 123,280
  • 14
  • 225
  • 444
Stefan Schouten
  • 249
  • 4
  • 14

2 Answers2

1

You can run an external program via a separate thread in your program and continue your program logic in your main thread, i.e. a multi-threaded application is a good solution.

Juvanis
  • 25,802
  • 5
  • 69
  • 87
  • Even if the program runs in another thread, I can't quit the program. Does this mean that, if I want to run a big memory-eating program, like games like Skyrim, it's running in the Java application, thus terminating the Java-app process, means terminating the external program? – Stefan Schouten Dec 06 '12 at 11:34
0

First destroy the subprocess :

Process proc = Runtime.getRuntime().exec("notepad.exe");
proc.destroy();

If this doesn't work, get the process id of the process and run a different subprocess to run kill <pid>

then exit java with System.exit(0); or normally.

Ozgen
  • 1,072
  • 10
  • 19