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?

2
  • possible duplicate of What is Daemon thread in java Commented Dec 6, 2012 at 0:22
  • Yes, but it's platform specific and very messy to achieve. Commented Dec 6, 2012 at 0:24

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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?
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.