问题描述
我正在尝试运行一个批处理文件,其中包含要重新启动的一组服务。当我从 Java 应用程序调用此批处理文件时,我收到中断异常。
我的批处理文件
call net stop app-service
call net start app-service
call net stop ui-service
call net start ui-service
call net stop custom-app
call net start custom-app
call net stop MSsqlSERVER /Y
call net start MSsqlSERVER
File file = new File(System.getProperty("user.dir") + File.separator + "restart.bat");
String time="cmd /c "+file.getAbsolutePath();
Process p = Runtime.getRuntime().exec(command);
int exitvalue = p.waitFor();
我收到以下错误
java.lang.InterruptedException
at java.lang.ProcessImpl.waitFor(ProcessImpl.java:451)
我做错了什么?
解决方法
看起来问题出在批处理文件上。立即调用停止和启动是导致问题的原因。确保 SQL 服务器和服务已停止,然后启动服务器和那些服务。
请检查此答案:
Stop and Start a service via batch or cmd file
使用SC(服务控制)命令,它给你更多的选择 不仅仅是开始和停止。
说明: SC 是一个命令行程序,用于与 NT 服务控制器和服务。用法: sc [命令] [服务名称] ...
The option <server> has the form "\\ServerName"
Further help on commands can be obtained by typing: "sc [command]"