我需要从我的 JSP 中执行一个批处理文件,但是代码在批处理文件执行语句之后移动到下一行,并且不等待批处理文件完成执行。我试过waitfor()
了,但它进入了无限循环。
所以现在我选择了一个不同的解决方案,我的批处理文件由 JSP 执行,修改了系统上的文件。所以我放了一个 while 循环并检查文件修改时间和当前系统时间。即使在这种情况下,while 循环也会永远持续下去。
请在任何一种方法中提供帮助。
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;
}
}