Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 为什么';这个批处理脚本不能执行吗?_Batch File - Fatal编程技术网

Batch file 为什么';这个批处理脚本不能执行吗?

Batch file 为什么';这个批处理脚本不能执行吗?,batch-file,Batch File,当我试图从cmd执行.bat脚本时,它什么也不做,cmd关闭。显然,服务的名称实际上不是myService,但我使用它作为匿名的占位符 我想做的是每隔3秒做5次检查,看看服务是否正确停止。然后我使用几个goto语句继续 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 (

当我试图从cmd执行.bat脚本时,它什么也不做,cmd关闭。显然,服务的名称实际上不是myService,但我使用它作为匿名的占位符

我想做的是每隔3秒做5次检查,看看服务是否正确停止。然后我使用几个goto语句继续

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
表示“退出命令”,因此一旦检测到“停止”,程序即退出


放下
退出
,它将按预期转到
:stopsuccess

您明确拥有一个退出命令。
GOTO:stopsuccess
将不会执行,因为您在它前面使用了EXIT。正如您所知,您不能强制中断FOR/L命令。无论IF语句是否为TRUE,它都将执行所有5次。
   exit goto :stopSuccess