Click here to Skip to main content
14,599,188 members
Rate this:
Please Sign up or sign in to vote.
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:
<pre>@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)

C:\Users>test.bat
This is GREEN COLOR
This is Red Color<
Posted
Updated 6-Nov-19 4:05am
Rate this:
Please Sign up or sign in to vote.

Solution 2

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[^].
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100