java.lang.InterruptedException 而 运行 一个批处理文件
java.lang.InterruptedException while running a batch file
我正在尝试 运行 一个批处理文件,其中包含我要重新启动的一组服务。当我从我的 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
我的java代码到运行批处理文件
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
Use the SC (service control) command, it gives you a lot more options
than just start & stop.
DESCRIPTION:
SC is a command line program used for communicating with the
NT Service Controller and services. USAGE:
sc [command] [service name] ...
The option <server> has the form "\ServerName"
Further help on commands can be obtained by typing: "sc [command]"
我正在尝试 运行 一个批处理文件,其中包含我要重新启动的一组服务。当我从我的 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
我的java代码到运行批处理文件
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
Use the SC (service control) command, it gives you a lot more options than just start & stop.
DESCRIPTION: SC is a command line program used for communicating with the NT Service Controller and services. USAGE: sc [command] [service name] ...
The option <server> has the form "\ServerName" Further help on commands can be obtained by typing: "sc [command]"