How to deploy an external process in java
I am trying to develop a new external process (like calculator) in Java. I am new to operating systems, but I found out that something like: can be used
Runtime.getRuntime ().exec ("C:\\Windows\\system32\\calc.exe");
. However, this does not actually trigger a new process. Is there anyway I can fork an external process using java?
+3
source to share
1 answer
I offer you ProcessBuilder
more Runtime.exec
. Also, if I understand your question, you can pass the full path to the exe file to yours ProcessBuilder
. Something like,
ProcessBuilder pb = new ProcessBuilder("C:\\Windows\\system32\\calc.exe");
pb.inheritIO(); // <-- passes IO from forked process.
try {
Process p = pb.start(); // <-- forkAndExec on Unix
p.waitFor(); // <-- waits for the forked process to complete.
} catch (Exception e) {
e.printStackTrace();
}
+3
source to share