I need to execute a batch file from my JSP, but the code moves to the next line after the batch file execution statement, and doesn't wait for the batch file to finish execution. I have tried waitfor()
, but it goes in infinite loop.
So now i have opted for a different solution, my batch file which is executed by JSP, modifies a file on system.So i have put a while loop and checking for the file modified time and current system time. Even in this case too,the while loop goes on for ever.
Please help in either approaches.
Process p = Runtime.getRuntime().exec("C:\\TOMCAT\\apache-tomcat-6.0.37\\webapps\\ROOT\\vcc_support_automation\\jsp\\List_user_utility.bat");
SimpleDateFormat sdfDate = new SimpleDateFormat("MM/dd/yyyy HH:mm");
Date now = new Date();
String strDate = sdfDate.format(now);
File file = new File("C:\\TOMCAT\\apache-tomcat-6.0.37\\webapps\\ROOT\\vcc_support_automation\\jsp\\duplicate_users_list.txt");
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm");
String mdfDate = sdf.format(file.lastModified());
strDate.replaceAll("\\s","");
mdfDate.replaceAll("\\s","");
while (true){
if(strDate.equals(mdfDate))
{
System.out.println("hello");
break;
}
}