Tuesday, March 18, 2014

Call a Batch file from Java

Following code can be used to run a batch file from java


public static void main(String[] args) {
// Running default target of ant script


try{
Runtime.getRuntime().exec("cmd /c C:\\Users\\arahi\\Desktop\\ant\\windows\\winInstall.bat");
System.out.println("executed");
Runtime.getRuntime().exec("cmd /c start C:\\Users\\arahi\\Desktop\\ant\\windows\\11g_SOA_Deploy_DEV.bat");
System.out.println("executedSoa");
}
catch (Exception ex) {


System.out.println( "Exception occured in embedded Java action ;" + ex );
}

}

This will open up a command console also when you will run this code.

No comments: