1

Is there any way to start non-Java process from Java and then stop it? Or at least send some keyinput to it (e.g. alt+f4)?

E.g. I start java app, then javaapp start notepad, then javaapp send alt+f4 to notepad. Javaapp will run from Administrator account.

Question is only about Windows OS.

1
  • Any way to get Process object that was started before java app started ? E.g. i start notepad, then i start java app, and java app get Process object for running notepad. Commented Jun 17, 2010 at 8:57

2 Answers 2

1

EDIT: missed question about starting...

To create, use Runtime.getRuntime().exec()

To destroy, use: Process.destroy() From the javadoc:

Kills the subprocess. The subprocess represented by this Process object is forcibly terminated.

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

1 Comment

No problem. I couldn't find an answer to your comment/addendum.
1

You can start a new process with Runtime.exec(). Then get the standard input of the returned process with Process.getOutputStream() and push input to it. In the end you can destroy() it.

Note that you must consume all output from the process to make it run correctly.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.