Windows批处理脚本:捕获用户反应"超时"命令 [英] windows batch scripting: catch user reaction to "timeout" command

查看:347
本文介绍了Windows批处理脚本:捕获用户反应"超时"命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道,通过使用暂停命令,我可以等指定的时间量;但我的问题是,如果这将是一个自动操作可能是由用户pvented $ P $是什么?我的意思是想我想做的操作的,但通过使用暂停命令,我等待,如果用户想取消该操作与否;比如在这个等待过程中,如果用户pressed回车键,然后批处理脚本执行别的东西(不操作A);

I know that by using the "timeout" command, I can wait for specified amount of time; but my question is that what if this would be an automatic operation that could be prevented by user? I mean suppose that I wanted to do the operation A but by using the "timeout" command I wait if user wants to cancel this operation or not; for example during this waiting process if user pressed the Enter key then batch script execute something else(not operation A);

推荐答案

暂停只是一个动作之前引起的延迟,而不是让用户选择的东西。我f您仍想使用它,你需要询问用户preSS控制-C超时命令之前打破,之后赶上ERRORLEVEL。

timeout is just to induce a delay before an action, not to let the user choose something. I f you still want to use it, you need to ask the user to press Control-C to break before the timeout command, and catch the ERRORLEVEL after that.

否则是你的朋友在这里:

Else choice is your friend here:

C:\Users\mm>CHOICE /T 10 /C yYcC /CS /D y  /M "Press y to validate, c to Cancel. You have 10 sec delay [Default y]:"
Press y to validate, c to Cancel. You have 10 sec delay [Default y]: [y,Y,c,C]?y

你还可以用ERRORLEVEL测试返回值。在这里,我pressed什么都没有,所以ÿ得到选择(通过/ D默认值)ERRORLEVEL为1(第一选项)。倒计时不会显示,虽然。

And you can test returned value with ERRORLEVEL. Here, I pressed nothing, so y get selected (default value via /D) and ERRORLEVEL is 1 (1st option). The countdown is not displayed though.

这篇关于Windows批处理脚本:捕获用户反应"超时"命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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