我使用Process Builder运行shell命令:
try {
ProcessBuilder lmBuilder = new ProcessBuilder("/home/istanbul/srilm/bin/i686-m64/ngram-count", "-text", modelPath, "-order", "3", "-lm", modelOutputPath);
lmBuilder.redirectErrorStream();
final Process lmProcess = lmBuilder.start();
int result = lmProcess.waitFor(); //result becomes 0
InputStream is = lmProcess.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
当我检查命令的输出时,我看到它正常工作。当我通过shell运行它时,我看到了输出:
warning: discount coeff 1 is out of range: 0
warning: discount coeff 7 is out of range: 1.06876
warning: discount coeff 7 is out of range: 2.09945
但是,当我通过流程构建器运行时,我看不到任何输出。
有什么想法吗?
答案 0 :(得分:2)
lmBuilder.redirectErrorStream();
这是不正确的。
此方法仅告诉是否将stderr重定向到stdout;它没有指示应该将stderr重定向到它。
你应该使用的是:
lmBuilder.redirectErrorStream(true);