gpt4 book ai didi

java - ProcessBuilder 不输出任何内容

转载 作者:行者123 更新时间:2023-12-01 18:16:00 25 4
gpt4 key购买 nike

我使用 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

但是,当我通过流程构建器运行它时,我看不到任何输出

有什么想法吗?

最佳答案

lmBuilder.redirectErrorStream();

这是不正确的。

此方法仅告诉您是否将 stderr 重定向到 stdout;它并不指示 stderr 应重定向到它。

你应该使用的是:

lmBuilder.redirectErrorStream(true);

关于java - ProcessBuilder 不输出任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29462362/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com