1 Reply Latest reply: Mar 26, 2013 8:35 AM by gimbal2 RSS


      hello , i have 3 versions of java ie. jdk1.6.0_23 , jdk1.6.0_27 , jre6

      i have removed java variable from " Path,Classpath "
      i have written code for this to get version of java i am using , my code is

      public static void execute(){
                Runtime runtime = Runtime.getRuntime();
                String directory = "D:\\program files\\Java\\jdk1.6.0_23\\bin";
                System.out.println("\"java -version\"");
                Process proc;
                try {
                     proc = runtime.exec(" java -version ", null, new File(directory));
                     BufferedReader input = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
                     String s = input.readLine();
                     String[] arr = s.split("\"");
                     for(String j : arr){
                } catch (IOException er) {
                     // TODO Auto-generated catch block

      but i am getting different version from the directory which i am giving to this program

      example : if i am in jdk1.6.0_23 it is giving me version like 1.6.0_35 , why is it so , if i am executing this

      Runtime.exec (" jar" , null , "new File(directory));
      it is printing proper results

        • 1. Re: Runtime.exec
          Well based on your test results you can draw a conclusion: apparently setting the working directory does not make the working directory the primary place to look for the executable to run; it (or rather: the OS) is still picking your "default" Java installation because that is the first one it finds on its search path. You'd have to put the full path to the executable you want to invoke in the first parameter to force a specific executable to be run. I'm not sure, but I believe using the Process class in stead of the Runtime class may also help if I remember correctly from similar threads posted not too long ago.