- #1
rathodnileshn
- 2
- 0
Hi all,
Suppose on computer 4 different versions of java are installed.
(1) Depending on the path of java.exe we can open command prompt go to path /jdk_version/bin/java.exe and type "java -version" and know the
particular version, But we can't extract the output of the command "java -version" into a file.
(2) Also using System.getProperty("java.lversion"); in java code we can get java version but it will return the version of the jvm that is running that
program. Or the path set to environment variable JAVA_HOME.
(3) Also following code can be used but it's not working:!(don't know why??)
import java.io.*;
import java.lang.*;
public class x
{
public static void main (String args[])
{
try
{
// get runtime environment and execute child process
Runtime systemShell = Runtime.getRuntime();
Process output = systemShell.exec("java -version");
// open reader to get output from process
BufferedReader br = new BufferedReader (new InputStreamReader(output.getInputStream()));
String line = null;
System.out.println("<OUTPUT/>");
while((line = br.readLine()) != null )
{ System.out.println(line); } // display process output
System.out.println("</OUTPUT>");
int exitVal = output.waitFor(); // get process exit value
System.out.println("Process Exit Value : "+ exitVal);
}
catch (IOException ioe){ System.err.println(ioe); }
catch (Throwable t) { t.printStackTrace();}
}
}
*** My requirement is :***
4 or more jdk are installed on OS. depending on path of java.exe I need to find it's version.
Can anybody help please?
Thanks in advance,
Nilesh Rathod.
Suppose on computer 4 different versions of java are installed.
(1) Depending on the path of java.exe we can open command prompt go to path /jdk_version/bin/java.exe and type "java -version" and know the
particular version, But we can't extract the output of the command "java -version" into a file.
(2) Also using System.getProperty("java.lversion"); in java code we can get java version but it will return the version of the jvm that is running that
program. Or the path set to environment variable JAVA_HOME.
(3) Also following code can be used but it's not working:!(don't know why??)
import java.io.*;
import java.lang.*;
public class x
{
public static void main (String args[])
{
try
{
// get runtime environment and execute child process
Runtime systemShell = Runtime.getRuntime();
Process output = systemShell.exec("java -version");
// open reader to get output from process
BufferedReader br = new BufferedReader (new InputStreamReader(output.getInputStream()));
String line = null;
System.out.println("<OUTPUT/>");
while((line = br.readLine()) != null )
{ System.out.println(line); } // display process output
System.out.println("</OUTPUT>");
int exitVal = output.waitFor(); // get process exit value
System.out.println("Process Exit Value : "+ exitVal);
}
catch (IOException ioe){ System.err.println(ioe); }
catch (Throwable t) { t.printStackTrace();}
}
}
*** My requirement is :***
4 or more jdk are installed on OS. depending on path of java.exe I need to find it's version.
Can anybody help please?
Thanks in advance,
Nilesh Rathod.