用户在Windows批处理文件中决定超时

前端之家收集整理的这篇文章主要介绍了用户在Windows批处理文件中决定超时前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我写了一个简单的.bat文件,一次询问用户是/否问题.现在我想添加一个超时 – 让我们说10秒 – .有一个简单的方法吗?

我的来源到目前为止:

SET /P ANSWER=Do you want it (Y/N)?
IF /i {%ANSWER%}=={y} GOTO :yes
IF /i {%ANSWER%}=={yes} GOTO :yes
GOTO :no

:yes
@echo Yeah,it will be done.
GOTO :continue

:no
@echo Nope,it will not happen.
GOTO :continue

:continue
@echo And on we go
这取决于您运行的Windows版本.不同的人运行不同的东西.

您可以尝试以下某些操作:

timeout 10

ping 0.0.0.0 -n 1 -w 10000 > nul

如果那些失败,你总是可以选择一个简单的循环(即如果选择有效)

:loop
choice /t 10 /c ynr /cs /d r /m "Do you want it (Y/N)?"
if errorlevel 3 goto :loop
if errorlevel 2 goto :no
if errorlevel 1 goto :yes

:yes
@echo Yeah,it will not happen.
GOTO :continue

:continue
@echo And on we go
原文链接:https://www.f2er.com/windows/371864.html

猜你在找的Windows相关文章