I am trying to make sure the batch file knows the service "Tomcat7" is fully stopped before trying to start the "Tomcat7" service again. I know "NET STOP" and "NET START" are supposed to wait to return until each have fully stopped or started, but I have seen cases where it continues on anyways, possibly due to a long timeout wait sometimes.
@ECHO OFF
net stop Tomcat7
rd /s /q "C:\storefront\live\work"
rd /s /q "C:\storefront\live\logs"
for /F "tokens=3 delims=: " %%H in ('sc query Tomcat7 ^| findstr " STATE"') do (
if /I "%%H" EQ "STOPPED" (
net start Tomcat7
)
)
if /I "%%H" EQ "STOPPED" (
. Should beEQU
instead ofEQ