execute bat file with arguments
Ok very simple task yet difficult for me as a novice to solve.
I have a bat file in a folder in my c: drive. This bat file call an EXE file inside the same folder. The BAT file also feeds some other files to teh EXE to run properly. The bat file works fine if I run it through command prompt.
I tried this code from eclipse but nothing happens i.e. Bat is not executed at all - where is the mistake?
Code :
import java.io.*;
import java.util.*;
public class utilities {
public static void main(String[] args) throws InterruptedException {
//cmd = cmd+" "+a+" "+b;
try {
String[] cmd = new String[]{"cmd.exe" ,"/c","C:\\EnergyPlusV6-0-0\\RunEplus.bat", "test5", "my"};
//cmd = new String[]{"cmd" ,"/c","C:\\EnergyPlusV6-0-0\\Epl-run.bat"};
Process p = Runtime.getRuntime().exec(cmd);
p.waitFor();
System.out.println(p.exitValue());
} catch (IOException e) {
e.printStackTrace();
}
}
Re: execute bat file with arguments
You should add code to look at the output and error Streams returned by the Process to see if there are any errors.