tags:

views:

99

answers:

3
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec(command);

I am running the batch file by means of the above lines in java. The command prompt will be opened. I need to close the command prompt using java code

Thanks

A: 
pr.destroy();
cadrian
+1  A: 
rt.exec("taskkill /IM cmd.exe");

or when you run your batch file

rt.exec("cmd /C batchfile.bat");

The second option is better in your situation. Less code, the command prompt exits once the batch is complete. The first option just kills an instance of cmd.exe open (which you may have multiple ones open).

to make sure it has finished running:

pr.waitFor();

-John

John T
it is existing at the beginning itself
A: 

Thanks a lot John T

If my answer fixed your problem simply mark it as the accepted answer =)
John T
but how do i know that batch file has run successfully