0

When using the CHOICE command, is there a way to make other code run at the same time?

For example, I am trying to create a timer that counts up. I want to make it so the choice option appears while the timer is sill running.

@echo off
set /a time=0
:up
cls
echo Time: %time%
echo Press "s" to start
CHOICE /c:s /n > nul
if errorlevel 1 goto run1
:run1
cls
echo Time: %time%
echo Press "p" to pause
ping localhost -n 2 >nul
set /a time=%time%+1
CHOICE /c:p /n > nul /t 1
if errorlevel 1 goto up
goto run1

If this question seems confusing or you don't know what I am asking, post a comment. I am trying to reword this question the best I can.

dan1st
  • 12,568
  • 8
  • 34
  • 67
I_boom5245
  • 21
  • 3

1 Answers1

0
@echo off
setlocal EnableDelayedExpansion

rem Get a CR control-char
for /F %%a in ('copy /Z "%~F0" NUL') do set "CR=%%a"

set /a time=0
cls
:up
echo/
echo Time: %time%
set /P "=Press "s" to start: " < NUL
CHOICE /c:s /n

:run1
set /a time=%time%+1
set /P "=Time: %time%, press "p" to pause:!CR!" < NUL
CHOICE /c:px /n /t 1 /d:x > nul
if errorlevel 2 goto run1
echo/
goto up
Aacini
  • 65,180
  • 12
  • 72
  • 108
  • Even though this code half worked for me, I am happy because I understand some of the commands a little better. – I_boom5245 May 20 '16 at 02:10