Search code examples
batch-fileinputsleepsimultaneous

Combination of `sleep` and `pause` command


Ok, after seeing crazy stuff being completed in so little code, I have high hopes this is possible.

Pretty much, I want to use the pause command normally, however, if the user doesn't input anything for a specified duration of time, it automatically continues.

In pseudo code:

(sleep %sleep-time%&Echo Pass)1>0 & pause

I thought at first I could do this using start /b to create a process that echoed input while being paused i the current thread, but that could cause problems if the user does input something.

Bonus

What would be really cool is if the errorlevel would be changed based on whether the user inputted something, or if the pause command timed out.


Solution

  • I suggest using timeout:

    timeout /T 60 >NUL
    

    This will sleep your script for 1 minute, or unless the user hits a key.