I want to execute a batch file from a java program.
I am using the following command.
Runtime.getRuntime().exec(\"server.bat\");
Bu
You can use ProcessBuilder for this. It provides much more control than exec
. Particularly, it allows to set working directory with method directory
.
Example:
ProcessBuilder pb = new ProcessBuilder("server.bat");
pb.directory(new File(deployDir + "\\com\\project\\util"));
Process p = pb.start();
int exitStatus = p.waitFor();
Of course, your app must get deployDir from somewhere. It can be set in environment, in application configuration file, it can be current user directory or anything else.