I am new to ProcessBuilder
. Today I am writing a simple application to execute the "java -version" but always got the IOException
.
ProcessBuilder pb = new ProcessBuilder("java -version");
try {
Map<String, String> map = pb.environment();
Process p = pb.start();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
The exception thrown as below
java.io.IOException: Cannot run program "java -version": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
I can ensure that JAVA_HOME
is set in environment variable, my eclipse is pointing to the jdk too.
JAVA_HOME=C:\JDK1.8.0_66-X64.
Can anyone tell what the problem is in my code/settings ?