Reputation: 770
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.
Upvotes: 1
Views: 780
Reputation: 20442
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.
Upvotes: 1
Reputation: 116306
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.
Upvotes: 1