Execute non-Java instructions from Java
Classes and methods to use
java.lang.Runtime#exec
The handling of the result is carried out using the returned java.lang.Process.
Code example
Process proc = Runtime.getRuntime().exec( "java --version" );
Execution example
jshell> Process proc = Runtime.getRuntime().exec( "java --version" );
proc ==> Process[pid=19916, exitValue="not exited"]
jshell> proc.exitValue();
$2 ==> 0
Input / output
Note that the method name is the viewpoint from the side that executed Process # exec **.
Output from the execution process
- Process#getInputStream
→ Get InputStream to get the contents output to the standard output by the process executed by Process # exec