runtime.getruntime().exec(batch file)
public class RunBatch
{
public static void main(String[] args)
{
String cmd = "C:/x.bat";
try
{
Process process = Runtime.getRuntime().exec(cmd);
System.out.println("execute batch file " + cmd);
int exitCode = process.waitFor();
System.out.println("exitCode = " + exitCode);
if (exitCode == 0)
{
System.out.println("successful");
}
else
{
System.out.println("failed");
}
}
catch(InterruptedException e)
{
e.printStackTrace();
}
catch(IOException e)
{
e.printStackTrace();
}
}
}
------------------------------------------------
C:/x.bat
net stop "Apache Tomcat 4.1" && net start "Apache Tomcat 4.1"
------------------------------------------------
当 Tomcat 服务处于停止状态的时候,运行 RunBatch.main()
因为在执行 net stop 的时候发生错误,它可以正常的监测到错误的发生
当 Tomcat 服务处于启动状态的时候,运行 RunBatch.main()
程序再 waitFor() 指出处于 blocked 状态,执行不下去了!!!!
各位达人帮帮忙!看看问题在什么地方?