【发布时间】:2012-12-10 06:33:18
【问题描述】:
在 JAVA 中使用 ProcessBuilder 我能够运行简单的终端命令,如 ls、pwd、echo 等..etc... 但是下面的代码被终止了,不知道为什么??
public static void main(String[] args) throws Exception
{
Runtime r = Runtime.getRuntime();
Process p = r.exec("echo 'T W O N E I G H T' | /home/saj/g2p/mosesdecoder-master/bin/moses -f /home/saj/g2p/working/binarised-model/moses.ini");
p.waitFor();
BufferedReader b = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = "";
while ((line = b.readLine()) != null)
{
System.out.println(line);
}
}
这个命令可以在终端上完美运行,运行大约需要 15 秒并给出输出。 我在 stackoverflow 上浏览过类似的主题,但没有找到任何帮助。 请在这方面提供帮助。 提前致谢。
【问题讨论】:
-
But following code is getting terminated...您遇到什么异常或错误?
标签: java eclipse ubuntu exec processbuilder