My batch script is not working. I want it to echo words in a different color every second, and I’m using Ansii escape codes for the colors. In the end, I came up with this piece of code:
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
chcp 65001
REM Define ANSI escape codes
SET "ESC="
REM Set initial values for color variables
set /a col1=0
set /a col2=0
set /a col3=0
REM Loop through a range of iterations
for /L %%i in (1,1,25000) do (
REM Print text with current color settings
echo %ESC%[38;2;!col1!;!col2!;!col3!m"█▓▒▒░░░Text Editor░░░▒▒▓█"
REM Pause
timeout /t 1 /nobreak > nul
REM Increment color variables
if !col1! LSS 255 (
set /a col1+=1
) else (
if !col2! LSS 255 (
set /a col2+=1
) else (
if !col3! LSS 255 (
set /a col3+=1
) else (
echo No more color combinations
pause
exit /b
)
)
)
)
I tried running it and saw the cursor move down to the next line every second, so this means its printing something, but i can’t see any words being printed to the console. Is anything wrong here?
i thought different codepages could not work with ansii escape codes, and tried that, but it did not work, then i tried with and without the delayed expansion, but it still did not work, i’m not very good at batch, so please help
Kyle Chong is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.