How to give different font colors in bat file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
dukdpk
Posts: 13
Joined: 10 Mar 2011 03:27

How to give different font colors in bat file

#1 Post by dukdpk » 17 Mar 2011 04:07

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

!k
Expert
Posts: 378
Joined: 17 Oct 2009 08:30
Location: Russia

Re: How to give different font colors in bat file

#2 Post by !k » 17 Mar 2011 09:00


jeb
Expert
Posts: 1055
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: How to give different font colors in bat file

#3 Post by jeb » 17 Mar 2011 09:44

@!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

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: How to give different font colors in bat file

#4 Post by aGerman » 17 Mar 2011 15:52

Congratulations, jeb. Nobody else thought about FINDSTR.

Regards
aGerman

phillid
Posts: 109
Joined: 03 Apr 2010 20:27
Location: Wellington, New Zealand
Contact:

Re: How to give different font colors in bat file

#5 Post by phillid » 19 Mar 2011 19:33

jeb wrote:Ansi.sys is to complex

I've always been confused by ANSI too :D

Post Reply