0

I'm trying to find the version of the OpenJDK installed in the system through C# code.

I tried the following, it works for Oracle's JDK, but not for OpenJDK

 try
       {
           ProcessStartInfo psi = new ProcessStartInfo();
           psi.FileName = "java.exe";
           psi.Arguments = " -version";
           psi.RedirectStandardError= true;
           psi.UseShellExecute = false;

           Process pr = Process.Start(psi);
           string strOutput = pr.StandardError.ReadLine().Split(' ')[2].Replace("\"", "");

           Console.WriteLine(strOutput);
       }
       catch (Exception ex)
       {
           Console.WriteLine("Exception is " + ex.Message);
       }

if the output of java -version is

openjdk version "1.8.0_202" OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_202-b08) OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.202-b08, mixed mode)

I want the output to be 1.8.0

0 Answers0