Java executes the bat batch file and closes the cmd window
Import Java.io.ioexception;public class Cmdmain {public static void main (string[] args) { //Execute batch file String Strcmd= "cmd/c start d:\\antrelease.bat"; Runtime RT = Runtime.getruntime (); Process PS = null; try { PS = rt.exec (strcmd); } catch (IOException E1) { e1.printstacktrace (); } try { ps.waitfor (); } catch (Interruptedexception e) { //TODO auto-generated catch block E.printstacktrace (); } int i = Ps.exitvalue (); if (i = = 0) { System.out.println ("execution done."); } else { System.out.println ("execution failed."); } Ps.destroy (); PS = null; After the batch finishes executing, kill the cmd window according to the Cmd.exe process name (this method is not easy to find, many of the online introduction is not valid) new Cmdmain (). KillProcess (); public void KillProcess () { Runtime RT = Runtime.getruntime (); Process p = null; try { rt.exec ("cmd.exe/c start WMIC process where name= ' cmd.exe ' call terminate"); } catch (IOException e) {
e.printstacktrace (); } }}
Java executes the bat batch file and closes the cmd window