如何使用Java检查已安装的dotnet core版本

huangapple go评论69阅读模式
英文:

How can I check the installed version of dotnet core using Java

问题

我正在编写一个Java应用程序,需要检查主机上安装的dotnet核心版本。我首先需要检查我的主机是Windows还是Linux,然后检查dotnet版本。在Java中是否有更简单的方法?

英文:

I am writing a java application where I need to check what is the installed version of dotnet core on the host machine. I need to first check whether my host machine is windows or Linux and then check the dotnet version. Is there a simpler way to do it in Java?

答案1

得分: 3

<br>
with

    Runtime runtime = Runtime.getRuntime();
        Process process = runtime.exec("dotnet --version");
        InputStream is = process.getInputStream();
        InputStreamReader isr = new InputStreamReader(is);
        BufferedReader br = new BufferedReader(isr);
        String line;

        while ((line = br.readLine()) != null) {
            System.out.println(line);
        }
英文:

<br>
with

Runtime runtime = Runtime.getRuntime();
    Process process = runtime.exec(&quot;dotnet --version&quot;);
    InputStream is = process.getInputStream();
    InputStreamReader isr = new InputStreamReader(is);
    BufferedReader br = new BufferedReader(isr);
    String line;

    while ((line = br.readLine()) != null) {
        System.out.println(line);
    }

you will get the version of your installed dotnet version.

huangapple
  • 本文由 发表于 2020年8月7日 18:10:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/63299668.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定