通过IDE(inteliJ)运行Shell脚本并接收:Linux的Windows子系统未安装发行版

时间:2019-07-11 16:21:49

标签: java windows shell sh

通过IDE(inteliJ)运行Shell脚本并接收:Linux的Windows子系统没有安装的发行版,为什么有任何想法?

我的代码:

public class TestScript {
    public static void main(String args[]) throws IOException, InterruptedException {
        String[] cmd = { "bash", "-c", "ExecutorTest.sh" };
        Process p = Runtime.getRuntime().exec(cmd);
        BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
        String line;
        while ((line = br.readLine()) != null) {
            System.out.println(line);
        }
        p.waitFor();
    }
}

输出:

Windows Subsystem for Linux has no installed distributions.

Distributions can be installed by visiting the Microsoft Store:

https://aka.ms/wslstore

1 个答案:

答案 0 :(得分:1)

要能够在Windows框上运行bash和bash脚本,需要安装Windows子系统。您可能要尝试安装它。或者,如果将bash脚本转换为Windows批处理脚本,则可以通过启动cmd来运行它。