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);
相关问题
- xcopy include folder
- Batch file if string starts by
- Jenkins - cmd is not recognized
- Timeout in authentication does not work properly
- String Manipulation with case sensitivity
相关文章
- How exactly do Firebase Analytics handle session d
- Extracting columns from text file using Perl one-l
- How can one batch file get the exit code of anothe
- rxjs timeout to first value
- How to make jenkins fail at a failing windows batc
- Problems using start-process to call other powersh
- Python utilizing multiple processors
- Why do all Pre-build or Post-build events in Visua
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: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.
choice.exe reference at ss64.com
As indicated by Aacini, no, timeout has been built without this feature.
This can be used as a workaround
This just starts two instances of timeout, one in background that is only cancelable with Ctrl+C and one in the active console. When the timeout command in console finished, tasklist is used to determine if the background timeout task is still active. If it is, then the visible timeout has been canceled, else timeout has been reached.
Wow! I always thought that this capability was inherent to
timeout
, but it is not! There is no way to know iftimeout
command ends because the time out or because a key press...However, it is possible to know if the time out was cancelled by Ctrl-C, instead by a normal key! In this case, the
errorlevel
value returned bytimeout
is different than zero:However, if you use this command inside a Batch file, the Ctrl-C press also cancel its execution! So the answer is: NO, there is no way to detect this point...
:-(