批次:如何提示输入,如果超时则继续? [英] Batch: How to prompt for input and continue if timed out?

查看:56
本文介绍了批次:如何提示输入,如果超时则继续?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 timeout/t 60 的方式来获得自动继续的延迟,并且 set/p var ="prompt" 来获取用户输入,但是有什么办法吗?改变两者兼而有之;问,如果没有输入任何内容,则有超时时间可以继续吗?我将其用于循环脚本的获取设置"屏幕,以更改脚本设置.

I know the timeout /t 60 way to get a delay with automatic continue and the set /p var="prompt" for getting user input but is there any change to do both; ask and have a timeout to continue if nothing is entered? I would use it for a sort of get set screen for my looping script to change script settings.

推荐答案

看看 choice/?以请求密钥并因超时而中止.

Take a look at choice /? to request a key and abort with a timeout.

例如:

CHOICE /T 10 /C YN /D Y

将等待10秒钟以等待Y(是)或N(否),否则将采用默认值(/D),在本示例中为Y(是).

will wait 10 seconds for Y (Yes) or N (No), otherwise the default (/D) will be taken, which is Y (Yes) in this example.

要检查结果(按键或默认值),必须检查%ERRORLEVEL%.

To check the result (either keypressed or default value), you have to check %ERRORLEVEL%.

@echo off
cls
CHOICE /T 5 /C YN /D Y
set _e=%ERRORLEVEL%
if %_e%==1 echo Y&goto :done
if %_e%==2 echo N&goto :done

echo Error
echo %_e%

:done

这篇关于批次:如何提示输入,如果超时则继续?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆