0

Im trying to run a basic batch countdown with user input to skip it (like a loading page that runs an animation and users can skip it if they want)

and I did my research over here.. I was using ping commands but that didn't gave me any option to get user selection.. than I moved to choice and found this helping article

How to ask for batch file user input with a timeout

the problem Im having is that the answer provided simply flashes the choice's text over the screen for a brief time.. any way to overcome this?

Edit: Here is the code that I use.. a b and c are examples but the pc will restart text flashes

@echo off
setlocal enableDelayedExpansion
for /l %%N in (1800 -1 1) do (
  set /a "min=%%N/60, sec=%%N%%60, n-=1"
  if !sec! lss 10 set sec=0!sec!
  choice /c:CN1 /n /m "PC will restart in !min!:!sec! - Press N to restart Now, or C to Cancel. " /t:0 /d:1
  cls
echo a
echo b
echo c
  choice /c:CN1 /n /m "PC will restart in !min!:!sec! - Press N to restart Now, or C to Cancel. " /t:1 /d:1
  if not errorlevel 3 goto :break
)
cls
echo PC will restart in 0:00 - Press N to restart Now, or C to Cancel.
:break
if errorlevel 2 (echo restarted) else echo Restart Canceled
pause>nul
Community
  • 1
  • 1
xDeathwing
  • 139
  • 13
  • Please edit your question and provide the code you are using. – Squashman Oct 21 '15 at 12:15
  • You cannot break out of a FOR /L command! It will iterate through the entire iterations regardless of what you try to do inside the code block. You choice command is only giving them one second to respond to the question as well. – Squashman Oct 21 '15 at 12:46
  • well I know I can't break our of for /L so thats why for waits for execution of choice.. and than moves on.. I want to find a way of breaking a for loop with an input.. that also doesn't flash – xDeathwing Oct 21 '15 at 12:59
  • Using `/t:0` might be related to "flash." Use `CHOICE /?` for more details. – lit Oct 21 '15 at 16:24

1 Answers1

0

As Squashman indicated: "You cannot break out of a FOR /L command!" so the solution is not "to find a way of breaking a for loop with an input", but to avoid the FOR /L loop:

@echo off
setlocal

set N=1800
:loop
  set /A "min=N/60, sec=N%%60, N-=1"
  if %sec% lss 10 set sec=0%sec%
  cls
echo a
echo b
echo c
  choice /c:CN1 /n /m "PC will restart in %min%:%sec% - Press N to restart Now, or C to Cancel. " /t:1 /d:1
if errorlevel 3 if %N% gtr 0 goto loop
cls
if errorlevel 2 (echo restarted) else echo Restart Canceled
pause>nul
Aacini
  • 65,180
  • 12
  • 72
  • 108
  • Well I would suggest you to try my code (which works) but even if using your method of goto loop it still flashes the choice text – xDeathwing Oct 21 '15 at 19:21