为什么进程exec()没有返回结果?

时间:2017-05-18 03:41:22

标签: java junit hamcrest

当我尝试通过执行命令的cmd运行JUnit测试时。它似乎可以直接在cmd中正确编写,但是当我尝试使用Process执行相同的命令时,没有任何反应。这是一些代码:

public static void main(String[] args) throws IOException, InterruptedException {
    String[] commands = new String[5];
    commands[0] = "cmd";
    commands[1] = "/c";
    commands[2] = "cd src_folder_path";
    commands[3] = "javac -cp .;lib/junit-4.12.jar ./models/java_file_toCompile.java .....";
    commands[4] = "java -cp .;lib/junit-4.12.jar.;lib/hamcrest-core-1.3.jar TestRunner";

    try {
        Process process = Runtime.getRuntime().exec(commands);
        BufferedReader inStreamReader = new BufferedReader(
            new InputStreamReader(process.getInputStream())
        );
        while (inStreamReader.readLine() != null) {
            System.out.println(inStreamReader.readLine());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

0 个答案:

没有答案