Click here to Skip to main content
15,947,785 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Code Project community,

In Batch Script, I am trying to print a specific line(using echo) in a specific color But when I try that, The whole command prompt is changing into that specific color. How to print the specific lines in different colors with out changing the color of whole command window?

Please note: 0A = GREEN, 0C = RED

What I have tried:

My Code:
BAT
@echo off
color 0A
echo This is GREEN COLOR
color 0C
echo This is Red Color


Output:(Print/changes every thing including the path and the file name also in Red color)
Terminal
C:\Users>test.bat
This is GREEN COLOR
This is Red Color<
Posted
Updated 8-Apr-23 13:53pm
v2

The color commands change the foreground and background colours for the entire command window. If you want colour changes on a line by line basis then you need to use ANSI escape sequences. See the section headed Set Display Attributes at ANSI/VT100 Terminal Control[^].
 
Share this answer
 
My article How to Change Text Color in a Windows Terminal[^] covers this and provides the code you need.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900