0
sc stop myService > nul
for /l %%A in (1,1,5) do (
for /f "tokens=3 delims=: " %%H in ('sc query "myService" ^|findstr "STATE"') do (
if /I "%%H" EQU "STOPPED" (
exit goto :stopSuccess
) else (
echo Checking if the Source Agent service has stopped successfully....
timeout 3 > nul
)
)
)
echo The service myService could not be stopped.
goto :error
:stopSuccess
sc delete myService > nul
当我尝试从cmd执行我的.bat脚本时,它不会执行任何操作并关闭cmd。显然,服务的名称实际上并不是myService,但我将它用作匿名的占位符。为什么不执行此批处理脚本?
我想要做的是做5间隔,间隔3秒,看看服务是否正常停止。然后我使用几个goto语句继续。
你明确地有一个EXIT命令。 'GOTO:stopsuccess'不会执行,因为您在前面使用了EXIT。 – Squashman
而且你也知道,你不能强制打破FOR/L命令。无论IF语句是TRUE,它都将执行5次。 – Squashman