title: Using ProcessBuilder to find version of Java
body: <p>I am trying to use Java to find out the versions of Java installed on a machine. I have:</p>
  
  <pre><code>List&lt;String&gt; commands = new ArrayList&lt;String&gt;();
  commands.add("java.exe");
  commands.add("-version");
  ProcessBuilder pb = new ProcessBuilder(commands);
  pb.directory(new File("C:\\Program Files\\Java\\jdk1.6.0_45\\bin"));
  Process p = pb.start();
  BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
  
  while ((s = stdInput.readLine()) != null) {
      System.out.println(s);
  }
  </code></pre>
  
  <p>However, when this is run, the while loop is never executed as the stdInput is empty. If I take out the <code>commands.add("-version")</code>, it will get the input that is output when running "java.exe" command on command line, so it seems adding the <code>-version</code> arguement is causing issues and this also indicates that the directory and java.exe commands are correct. Any help would be appreciated. </p>