Stefan Schouten
Stefan Schouten

Reputation: 349

Java, running external programs

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?

Upvotes: 1

Views: 603

Answers (2)

Ozgen
Ozgen

Reputation: 1092

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.

Upvotes: 0

Juvanis
Juvanis

Reputation: 25950

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.

Upvotes: 1

Related Questions