[英]Getting a Windows batch file to execute an application in background and then execute the next statement
[英]timeout /t 10 /nobreak > NUL is getting stuck and not coming out to execute next statement on windows 2003 server VM
“timeout /t 10 /nobreak > NUL”卡住了,无法执行下一条语句。 我写了一个下面的脚本,它在我的开发机器上按预期执行,也在少数测试机器上进行了测试。 它等待 10 秒,然后再次开始执行(也在安全模式下测试),但是在其中一台许可证已过期的Windows 2003 服务器上,我的脚本在安全模式下运行,但是在执行上述超时语句时它不会执行下一个声明。
有人可以告诉我原因(如果有的话)以及解决方案是什么?
set restart=1
...
... some other code
...
setlocal ENABLEDELAYEDEXPANSION
:WaitToRestart
if "%restart%"=="1" (
echo waiting for restart >> log.txt
shutdown /r /t 0
if "!errorlevel!" NEQ "0" (
echo error: !errorlevel! while restarting so wait for 10 sec >> log.txt
timeout /t 10 /nobreak > NUL
goto WaitToRestart
)
echo error: !errorlevel! you shuld not be here to see after death >> log.txt
)
setlocal DisableDelayedExpansion
在我的开发机器上,此脚本运行良好(Windows 10),但卡在 Windows 2003 上的生产环境中(它作为启动脚本运行,在安全模式下启动后运行)。
因此,我使用命令“PING localhost -n 6 >NUL”更改了“超时”命令,但它在旋转 10、12 次后也卡住了。 当我删除“PING”命令时,它也会旋转很长时间,直到命令“关闭”成功执行。
看起来像是特定于机器的问题,可能由于许可证过期问题而停止,因为我从物理机的备份创建了 VM
如果你只是想获得一个等待功能,你可以操纵ping
来做到这一点。
ping 0 -w 1000 -n 10 >nul
将其逐个分解, cmd 将0
扩展为0.0.0.0
,这是 cmd 将尝试 ping 的 IP 地址(它不存在)。 -w
指定在请求超时之前ping
将等待的毫秒数。 -n
指定您要发送的请求数量(因此您的总持续时间,以秒为单位是w/1000 * n
)。 >nul
不是ping
特定的; 它使到控制台的输出无效。
通过 ping 一个不存在的 IP,您可以强制ping
对每个请求超时,从而获得可靠的等待时间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.