我正在运行该程序,但是它有一个错误,例如“ * .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();
}
}
}