1

I was wondering if there was a command to automatically exit a batch file if it is left alone for a certain number of seconds.

I made a little program similar to the one found here. Most of the coding I used is displayed on the page, but it basically asks you what website you want to visit, and selecting one of the options opens a browser window with the desired page. however, after selecting one of the listed sites, the program displays the options to either exit or return to the top. This is where I usually forget about it until I close whatever I was looking at, and the batch is still open in the background.

So is there anyway to set a auto-exit timer without it interrupting the user, and without restricting the ability to go back and select another option?

Thanks!

Mark Gamez
  • 13
  • 3
  • http://stackoverflow.com/a/4340058/548036 answer by @daniel11 could have the answer (TIMEOUT /T 3600 /NOBREAK) – Mo Patel Sep 01 '14 at 19:45
  • No you don't want `timeout`, you want `choice`.: http://stackoverflow.com/questions/12331428/how-to-ask-for-batch-file-user-input-with-a-timeout – indiv Sep 01 '14 at 19:47
  • You could also multi-thread and force terminate. But that would be for a complicated task – Monacraft Sep 02 '14 at 00:00

2 Answers2

2

You can use choice command, instead set /p

Where z is an automatic option, you can use another letter.

/D is the default option if time is passed. /T is the time to wait (this case, 5 seconds).

choice /n /c:zbe /T 5 /D x /M "Make your selection"

Then use it on your code:

choice /n /c:xbe /T 5 /D x  /M "Make your selection"
if errorlevel 1 exit
if errorlevel 2 goto :option_b
if errorlevel 3 goto :option_e

More info type in cmd: choice /?

Honguito98
  • 664
  • 8
  • 13
1

Please take a look here

set /p udefine=

this line is waiting for b or e

Since you only want to exit the batch file after selecting one website, you can just wipe these lines

echo Type [e] to exit or [b] to go back and select another site.
echo.
set /p udefine=
echo.
echo ***************************************************************
if %udefine%==b goto top
if %udefine%==e goto exit
:exit
cls
echo ***************************************************************

and also this line (before the last one)

pause
Fabrice T
  • 648
  • 9
  • 23