Showing a continuous countdown while executing other commands in background

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
DOSadnie
Posts: 143
Joined: 21 Jul 2022 15:12
Location: Coding Kindergarten

Showing a continuous countdown while executing other commands in background

#1 Post by DOSadnie » 13 Oct 2023 10:50

Is it possible at all using just a single window created by BAT or PS1 script to see one rather long countdown while in the background the very same file will be firing up other commands? And if the user decided to interrupt the whole process to be able to close that window thus effectively stopping whatever commands are left from being ever executed?

Or will I have to use some e.g. AHK script that will show me a Windows Console window containing just a countdown, and which AHK script upon detecting closure of closure of that window will stop further instructions of this AHK?

miskox
Posts: 631
Joined: 28 Jun 2010 03:46

Re: Showing a continuous countdown while executing other commands in background

#2 Post by miskox » 13 Oct 2023 11:22

You could use a progress bar. See:

viewtopic.php?t=5503
with this:
viewtopic.php?p=33575#p33575

Now Escape sequences should be used instead of an .exe.

viewtopic.php?t=3495
viewtopic.php?t=10400
viewtopic.php?t=274

You could also add this info to the Console Window's Title

Saso

DOSadnie
Posts: 143
Joined: 21 Jul 2022 15:12
Location: Coding Kindergarten

Re: Showing a continuous countdown while executing other commands in background

#3 Post by DOSadnie » 16 Oct 2023 11:05

I see there are some options in doing this, thank you

But as they seem too complex for my limited skills, for now I will most likely be using something simple as this:

Code: Select all

@echo off
setlocal enabledelayedexpansion

:: Set the length of the countdown:
set LENGTH_OF_THE_INITIAL_COUNTDOWN=2

:: Initial message:
echo.
echo.   C O M M E N C I N G   T H E   S C R I P T :
echo.
echo.   Press any key to cancel
echo.   

:: Check if the output ends with zero that is not preceded by another digit:
timeout /t %LENGTH_OF_THE_INITIAL_COUNTDOWN% >nul 2>nul

:: Terminate this script if no trailing 0 is found:
if errorlevel 1 exit /b

:: Place for other commands that are to be executed after the countdown:

set "STEADY_NON_FLASHING_MESSAGE=   E X E C U T I N G :"
echo.
echo.
echo.!STEADY_NON_FLASHING_MESSAGE!
echo.   

timeout /t 1 >nul 2>nul

:: Calculator:
echo.   ^> Calculator
echo.   
timeout /t 1 >nul 2>nul
start "" /b /min calc.exe

:: Microsoft Screen Magnifier:
echo.   ^> Magnifier
echo. 
timeout /t 1 >nul 2>nul
start "" /b magnify.exe

:: Notepad:
echo.   ^> Notepad
echo.   
timeout /t 1 >nul 2>nul
start "" /b /min notepad.exe

:: Accessibility On-Screen Keyboard:
echo.   ^> Virtual Keyboard
echo.   
timeout /t 1 >nul 2>nul
start "" /b osk.exe

:: Closing message:
set "END_MESSAGE=   T H E   E N D :"
echo.
echo.
echo.!END_MESSAGE!
echo.
echo.   Finished executing the script
echo.

:: End the script:
pause >nul
:: timeout /t 3 >nul 2>nul
:: exit /b
which I reckon in time I will be able expand into having an indicator of how many executions are listed in the file and which one is taking place in a given moment

Post Reply