I am currently trying to execute a .bat file in Java. The bat file actually runs perfectly but after it is executed, my main program exits. I have no idea why and i need it to carry on with its code once the bat file has been executed. The program and bat file will all be run on Windows. Here is the code to how i run the bat file:
if(!running) {
@SuppressWarnings("unused")
Process process = Runtime.getRuntime().exec("cmd /c start "+localTargetInPath+"\\startBatchClient.bat");
process.getInputStream().close();
process.getOutputStream().close();
process.getErrorStream().close();
}
//wait to allow batch client to start up
Thread.sleep(1000);
I have been trying to figure this out for days with no luck. Any ideas?
EDIT:
Just to clarify something stated in answers:
The point is to do the following:
- Run batch file
- batch file launches batch client
- Java program continues to run
- Java program connects to running batch client
EDIT 2:
Here is the contents of the batch file (which again runs the application without any problems:
set JAVA_HOME="C:\Program Files\Java\jdk1.6.0_23"
set ep_root=C:\app\plm\e6_1_1\P2\BatchClient
set axalant_root=C:\app\plm\e6_1_1\P2\BatchClient\axalant
set batchcli_root=C:\app\plm\e6_1_1\P2\BatchClient
set EP_MACH=intel-ms-nt4.0
C:\Windows\system32\cmd.exe /K c:\app\plm\e6_1_1\P2\BatchClient\axalant\cmd\batchclient_nowrapper.cmd -eciservermode -p %localInPath%\batchClient.properties -T C:\zftmp\svc.emea.batch11e\testclient.properties