开发者

Couldn't run bat file through Java code

Problem is that the same code below is working on other machine with Windows 7. I also use Windows 7, and bat file works well. But if I try to run this bat from code written before, cmd window just blink once and disappear.

s =  path + "makeInfomap.bat";  

try {   
    p = run.exec(s); 
} catch (Exception e) {
    System.out.println(e);  
    e.开发者_运维知识库printStackTrace(); 
}  

final int exitVal = p.waitFor();


Run don't walk to this link: When Runtime.exec() won't.

It will tell you how to gobble output and error streams and will tell you how to call the OS's command interpreter when doing similar programs (although it is a little out of date).


My guess is that java is calling it fine but that the batch file itself is running in to trouble.

Try adding a 'pause' as the last line of your batch file and see if the batch file's console gives you any usable information.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜