Using ProcessBuilder to find version of Java -
i trying use java find out versions of java installed on machine. have:
list<string> commands = new arraylist<string>(); 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); } however, when run, while loop never executed stdinput empty. if take out commands.add("-version"), input output when running "java.exe" command on command line, seems adding -version arguement causing issues , indicates directory , java.exe commands correct. appreciated.
the output of java -version sent error stream - reading stream should result in proper output:
bufferedreader stdinput = new bufferedreader(new inputstreamreader(p.geterrorstream())); alternatively, can call redirecterrorstream(true) merge input , error streams. if wish print command line, can use inheritio on processbuilder.
the running java version can found without need processbuilder retrieving appropriate system property
system.out.println(system.getproperty("java.version"));
Comments
Post a Comment