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.
精彩评论