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.
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
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.
Please check this answer:
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]"