Vladimir
Vladimir

Reputation: 1

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();

Upvotes: 0

Views: 636

Answers (2)

Hovercraft Full Of Eels
Hovercraft Full Of Eels

Reputation: 285403

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).

Upvotes: 2

Roy Truelove
Roy Truelove

Reputation: 22456

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.

Upvotes: 0

Related Questions