当我运行这段代码并且调用图非常大时,程序会打印到opt
输出的最后一行,并在 处被阻塞readLine
,即使什么都没有。有谁知道问题是什么?opt -print-callgraph file
将调用图发送到错误流。我尝试执行opt -print-callgraph file 2> callgraph
以便可以从文件中读取,但它抱怨位置参数太多。
奇怪的是,代码对于小尺寸的调用图运行良好。
我也尝试过使用ProcessBuilder
,但我遇到了同样的问题。
Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec("opt -print-callgraph " + file);
BufferedReader in = new BufferedReader(new InputStreamReader(process.getErrorStream()));
String s = null;
try {
// Gets stuck at readLine after printing out the last line.
while ((s = in.readLine()) != null) {
System.out.println(s);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
in.close();
}