首页 > 解决方案 > 有没有办法让 test.Bat 文件保持打开并运行其余代码?

问题描述

我在下面有这段代码-执行批处理文件但程序不会执行其余代码,而是保留在批处理文件本身中。我想要实现的是在执行其余代码的同时运行此 BATCH 文件。

public class CmdJava {
    public static void main(String[] args) throws IOException {
        Process p = Runtime.getRuntime().exec("cmd /c call README.bat");
        
        String s;
        System.out.println(p.getOutputStream());
        BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
        while ((s = stdInput.readLine()) != null) {
            System.out.println(s);
//code reaches and stops at this line as the batch file need to be forcefully closed
        }
        System.out.print("Need to reach this code");
    }
}

任何帮助是极大的赞赏

标签: javamavenbatch-fileruntime.execseq

解决方案


推荐阅读