Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: Colour code TEXT in a batch file!

3 Weeks Ago   #1
Paul Black

7 HP SP1 64-bit Vista HB SP2 32-bit Linux Mint 18.3
 
 
Colour code TEXT in a batch file!

Good afternoon,

I have written a batch file which works great!
However, I would like to colour several pieces of text within the batch file.
I have spent a LONG time researching this on Google and I am almost there.

This is what I have at the top of the code...

Code:
@echo off
 
SETLOCAL EnableDelayedExpansion
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
  set "DEL=%%a"
)
This is what I have as an example that I want to colour red [which it does]...

Code:
call :ColorText 0c "     IMPORTANT - Numbers 2 blah blah."
call :ColorText 0c "                    If you blah blah!" & set /p ".= " < nul
echo.
This is what I have as the :ColorText code...

Code:
:ColorText
rem echo off
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1
GOTO :EOF
The questions I have are...

[1] If I put a colon [:] after Important, is doesn't work, hence the dash [-]?
[2] Why will it not show the exclamation [!] at the end of the line although it is there?
[3] Why will it not show the full stop [.] at the end of the line although it is there?
[4] Is there a way to split the call :ColorText 0c " IMPORTANT - Numbers 2 blah blah." over two lines so it makes it esaier to read and also lines up in the script with the code below it. I tried several options, all to no avail!
[5] As you see from the middle piece of code, the Numbers 2 and If you are not lined up, but they are in the consol!
[6] Why doesn't it put a blank row after even though there is a echo. after the text to be coloured, but it does if I use & set /p ".= " < nul end & echo..
[7] It will also not accept forward slash [/]!

Thanks in advance.


My System SpecsSystem Spec
.
3 Weeks Ago   #2
samuria

win 8 32 bit
 
 

Does color 2 work


0 = Black 8 = Gray 1 = Blue 9 = Light Blue 2 = Green A = Light Green 3 = Aqua B = Light Aqua 4 = Red C = Light Red 5 = Purple D = Light Purple 6 = Yellow E = Light Yellow 7 = White F = Bright White
My System SpecsSystem Spec
3 Weeks Ago   #3
Paul Black

7 HP SP1 64-bit Vista HB SP2 32-bit Linux Mint 18.3
 
 

Hi samuria, thanks for the reply,

Quote   Quote: Originally Posted by samuria View Post
Does color 2 work

0 = Black 8 = Gray 1 = Blue 9 = Light Blue 2 = Green A = Light Green 3 = Aqua B = Light Aqua 4 = Red C = Light Red 5 = Purple D = Light Purple 6 = Yellow E = Light Yellow 7 = White F = Bright White
The colour is not the problem!

I think it is the parameters that are stopping what I have posted in the numbered comments/questions!
My System SpecsSystem Spec
.

3 Weeks Ago   #4
Barman58

Windows 10 Pro x64 x3, Ubuntu
 
 

Paul, the Command line DOS language used to write batch files has a number of "protected" or System Characters. There are ways to get around these limitations

Take a look here as a starting point to future research Batch files - Escape Characters also check the left menu for good tips and suggestions for Batch scripting

You may also find a specific editor better for writing code than Notepad Notepad++ is an old one Notepad++ v7.6.6 - Current Version that can be setup to format code and comments to show more clearly

EDIT

Batch Editor download | SourceForge.net is an opensource specific Batch File Editor
My System SpecsSystem Spec
3 Weeks Ago   #5
Paul Black

7 HP SP1 64-bit Vista HB SP2 32-bit Linux Mint 18.3
 
 

Hi Barman58, thanks for the reply, it is appreciated!

Quote   Quote: Originally Posted by Barman58 View Post
Paul, the Command line DOS language used to write batch files has a number of "protected" or System Characters. There are ways to get around these limitations.
I have had a quick look at the batch link you posted but I need to look at it in more detail.

I only have about a dozen lines of text that I actually want to colour. The thing is, I need exclamation [!], colon [:] and full stop [.] to be accepted within the colour parameters because they are included in the lines of text which are at present after the echo. It is harder to achieve this than I thought it would be.
My System SpecsSystem Spec
3 Weeks Ago   #6
Barman58

Windows 10 Pro x64 x3, Ubuntu
 
 

You could try a single quote as a delimiter either end of the text string that should designate everything between the quotes as a part of the text or maybe use the ASCII code for the symbols with a delimiter - you may need to use one of the modifiers mentioned in the link -

I wish I could remember how exactly I wrote the Batch Files back in the 80's - used to produce menus for old pre-windows systems to allow the typists to access various programs, without needing to remember the names
My System SpecsSystem Spec
3 Weeks Ago   #7
Paul Black

7 HP SP1 64-bit Vista HB SP2 32-bit Linux Mint 18.3
 
 

Hi Barman58,

Quote   Quote: Originally Posted by Barman58 View Post
You could try a single quote as a delimiter either end of the text string that should designate everything between the quotes as a part of the text or maybe use the ASCII code for the symbols with a delimiter - you may need to use one of the modifiers mentioned in the link.
Thanks again for the reply.

I have tried numerous combinations of characters etc to try and get this working. I just can't seem to get the correct delimiter!
I will look at the link again later and do some more investigating!
I could live with just getting the full stop to work at the end of the sentences!
My System SpecsSystem Spec
2 Weeks Ago   #8
Paul Black

7 HP SP1 64-bit Vista HB SP2 32-bit Linux Mint 18.3
 
 

Hi everyone,

I am still no nearer to resolving this!
Has anyone got any other ideas please?

Thanks in advance.
My System SpecsSystem Spec
2 Weeks Ago   #9
SIW2

Microsoft Community Contributor Award Recipient

Vista x64 / 7 X64
 
 

As far as I know, what you are trying to do isn't natively supported.Unless you want to use some kind of software add on, you are wasting your time.
My System SpecsSystem Spec
2 Weeks Ago   #10
Paul Black

7 HP SP1 64-bit Vista HB SP2 32-bit Linux Mint 18.3
 
 

Hi SIW2,

Quote   Quote: Originally Posted by SIW2 View Post
As far as I know, what you are trying to do isn't natively supported. Unless you want to use some kind of software add on, you are wasting your time.
OK, thanks SIW2, that is good enough for me. It is not important but it would have been nice! I don't want to use some kind of software add on so I will mark this thread as solved.
Thanks again .
My System SpecsSystem Spec
Reply

 Colour code TEXT in a batch file!




Thread Tools




Similar help and support threads
Thread Forum
batch file text help
I am trying to create a task using a batch file which i can then add to my windows task manager so that i can schedule it run every 7 days. I need the file to delet anything which is contained within the scanned documents folder. The folder is located on a network and shared by other users. ...
General Discussion
Batch file code has problems.
My batch file isnt working. In the middle of running, it skips a big part of code and goes to the last few lines. Help? echo Retrieving data... ping 127.0.0.1 -n 2 -w 3000 > NUL echo -e "2B5sfyZC9a1hCxO" ping 127.0.0.1 -n 2 -w 1000 > NUL echo -e "76BE8Td6rhoaSw2" ping 127.0.0.1 -n 2 -w 1000 >...
General Discussion
Batch File that grabs file names from folder to insert into batch file
Ok I'm totally at a loss on how to word this so I'm just going to write it out the best that I can... :confused: First I have a batch file that I'm writing that will convert mp4 files to mp3 files (I have a lot) for a buddies band using ffmpeg. Here's the code that I'm using: ffmpeg -i...
General Discussion
Please help with batch or VBS file code
Hello folks, I really need some help. I have been trying a number of ways but do not have enough experience or knowledge of the code for this. I am trying to create a batch file or VBS file that can change this: C:\Downloads\Albums\Work Folder\Album - January\Random Junk Subfolder\Multiple...
General Discussion
Title bar text colour
How do I change the title bar text colour? I can change all the other font colours in Advanced Appearance Settings, but not for a maximized box (only for non-maximized). Am I missing something obvious? I've got a blue colour scheme and would like to change the title bar text to white. As I...
Customization


Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 21:52.
Twitter Facebook