How to get the current Java version available?

后端 未结 3 957
清歌不尽
清歌不尽 2021-01-20 06:36

How do i get the current Java version available using c#?

I have been able to find a way to get the java version on my PC using C# but I need to be able to compare

3条回答
  •  礼貌的吻别
    2021-01-20 07:03

    Try:

    ProcessStartInfo psi = new ProcessStartInfo();
    psi.FileName = "javac";
    psi.UseShellExecute = true;
    psi.RedirectStandardError = true;
    
    psi.Arguments = "-version";
    Process p = Process.Start(psi);
    string strOutput = p.StandardError.ReadToEnd();
    p.WaitForExit();
    

    Then you should parse the string of output. This output normally looks like:

    javac 1.6.0_27
    

    In case you are interested in the Runtime Environment (RE), replace javac with java

提交回复
热议问题