使用“ Runtime.getRuntime()。exec(cmd)”执行protoc任务时,ti有一个错误

时间:2019-03-27 08:57:51

标签: java proto

我正在运行该程序,但是它有一个错误,例如“ * .proto:无效的参数”。但是当我在cmd中运行它时,就可以了!

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;

public class Test {

    public static void main(String[] args) throws InterruptedException {
        String cmd = "cmd /c cd D:/work/miliao/codes/miliao-stress-test/src/main/proto && protoc --descriptor_set_out proto.desc --include_imports *.proto";
        try {
             Process proc = Runtime.getRuntime().exec(cmd);
            int exitVal = proc.waitFor();
            System.out.println(exitVal == 0 ? "success" : "failed");
            System.out.println(exitVal);

            Reader reader = new InputStreamReader(proc.getErrorStream());
            BufferedReader bf = new BufferedReader(reader);
            String line = null;
            while((line=bf.readLine())!=null) {
                System.out.println(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}

0 个答案:

没有答案