仅在终止Java程序后才执行DOS命令

时间:2014-11-05 15:27:02

标签: java process command runtime exec

对不起,伙计们,我是这个网站的新来者,我不熟悉它。我昨天发布了这个问题,但标题和代码格式都不好。以下是更好的。

我有一个名为dtm-win32的可执行程序。我想用java程序来运行它。通常,此可执行程序至少需要运行20分钟,并且在命令行中有一个大输出字符串。以下是我的java代码片段(隐藏了try catch块):

String command = "dtm-win32 --ntopics 20 ...” ;    
//Please note that the command is too long to show its complete format. So I don't show the complete format here and it's not relevant to solving this question.
Process process = Runtime.getRuntime().exec(command);
BufferedReader br = new BufferedReader(new InputstreamReader(process.getInputStream()));
String s;
while ((s = br.readLine()) != null) {
    System.out.println(s);
}    
br.close();    
process.waitFor();

我的操作系统是Windows 7,我的jdk是jdk1.7.0_51。

我遇到了一个有趣的问题:java程序成功启动dtm-win32,但是,我看不到任何要打印的内容,而dtm-win32似乎被阻止了。所以我终止了java程序。令我惊讶的是,目前我终止了我的java程序,dtm-win32恢复正常运行!我试过多次运行但是偶尔会发生这种情况。他们之前遇到类似问题的人是谁?

0 个答案:

没有答案