[英]java.lang.InterruptedException while running a batch file
I am trying to run a batch file which has set of services I want to restart.我正在尝试运行一个批处理文件,其中包含我要重新启动的一组服务。 When I call this batch file from my Java application I get Interrupted Exception.
当我从我的 Java 应用程序调用这个批处理文件时,我得到了中断异常。
My batch file我的批处理文件
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
My java code to run the batch file我的 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();
I'm getting the following error我收到以下错误
java.lang.InterruptedException
at java.lang.ProcessImpl.waitFor(ProcessImpl.java:451)
What am I doing wrong?我究竟做错了什么?
Looks like the problem is with the batch file.看起来问题出在批处理文件上。 Calling stop and start immediately is what's causing the issue.
立即调用停止和启动是导致问题的原因。 Make sure the SQL server and services are stopped, then start the server and those services.
确保 SQL 服务器和服务已停止,然后启动服务器和这些服务。
Please check this answer:请检查这个答案:
Stop and Start a service via batch or cmd file 通过批处理或 cmd 文件停止和启动服务
Use the SC (service control) command, it gives you a lot more options than just start & stop.
使用 SC(服务控制)命令,它为您提供了比启动和停止更多的选项。
DESCRIPTION: SC is a command line program used for communicating with the NT Service Controller and services.
说明:SC 是一个命令行程序,用于与 NT 服务 Controller 和服务进行通信。 USAGE: sc [command] [service name]...
用法:sc [命令] [服务名称] ...
The option <server> has the form "\\ServerName" Further help on commands can be obtained by typing: "sc [command]"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.