Page 1 of 1

How to give different font colors in bat file

Posted: 17 Mar 2011 04:07
by dukdpk
Hi All

I want to give different font colours for some of the texts in bat file. Please look at the following bat file.

@echo off

echo List of Reports
echo Staff List
echo Responsible Works

pause


I want to give red colour for "List of Report" text and green colour for both "Staff List" and "Responsible Works" texts. Please advice me how to do it.

Thank You

Re: How to give different font colors in bat file

Posted: 17 Mar 2011 09:00
by !k

Re: How to give different font colors in bat file

Posted: 17 Mar 2011 09:44
by jeb
@!k Ansi.sys is to complex 8)

Try this simple pure batch solution

Code: Select all

@echo off
SETLOCAL DisableDelayedExpansion
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
  set "DEL=%%a"
)


call :ColorText 0C "List of Reports"
call :ColorText 0a "Staff List"
call :ColorText 0b "Responsible Works"
goto :eof

:ColorText
echo off
<nul set /p .=. > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
echo(%DEL%%DEL%%DEL%
del "%~2" > nul 2>&1
goto :eof


Output
List of Reports
Staff List
Responsible Works


hope it helps
jeb

Re: How to give different font colors in bat file

Posted: 17 Mar 2011 15:52
by aGerman
Congratulations, jeb. Nobody else thought about FINDSTR.

Regards
aGerman

Re: How to give different font colors in bat file

Posted: 19 Mar 2011 19:33
by phillid
jeb wrote:Ansi.sys is to complex

I've always been confused by ANSI too :D