Can I create a 'set /p “”=' command with a timer in Cmd?

后端 未结 2 847
野的像风
野的像风 2020-12-06 23:24

I want to create a timer for the \'set /p \"\"=\' command so that if you don\'t input something in the required time space it moves to a different label.

Eg.

2条回答
  •  北海茫月
    2020-12-07 00:24

    Squashman's suggestion is the best one that comes to mind for me as well. Save the following .bat script and run it, and see whether it offers the user experience you had in mind.

    @echo off
    setlocal
    
    set /P "=You have 3 seconds to type 'go': "NUL
    
        rem // Extended character probably isn't on the keyboard.
        rem // If the result was the extended char, it was timed out.
        if errorlevel 2 goto fail
    
        rem // visual response of user input w/o new line
        set /P "=%%I"

提交回复
热议问题