Please enter your login details.

Colourful Commands
(Monday 21st of November 2011 11:00:58 AM) (4591 views) (0 comments)

Have you ever tried to achieve coloured output in cmd.exe on a modern windows OS? I recently tried to do this on Windows 7 and found it extremely difficult to achieve from a scripting environment. So, I decided to create a solution

Under Linux, Unix and DOS a set of special commands called ANSI/VT100 escape sequences can be used to control the command terminal attributes. Under Windows these can be emulated using something like Cygwin. However, if you're restricted to cmd.exe your options are limited. Especially if you want a simple setup procedure for end users.

The Windows API contains a function called SetConsoleTextAttribute which allows any application to change some basic console attributes including the colour of foreground text. My solution wraps this function in a tiny executable package so that it can be used by batch files and other scripting environments.

The download, including source code, can be found here: (1554 downloads)

And here's some example usage..
@echo off col -praw col -graw set DEFATTRIBS=%ERRORLEVEL% col -fg=rgi @echo Some text in yellow.. col -add -bg=bi @echo Adding a blue background. col -sraw=%DEFATTRIBS% @echo And now restored to whatever your defaults were! @echo on

Let me know if you find any problems, I'm happy to try out any suggestions you may have

Please login to post comments.

Copyright © 2011 Christopher James Plant Page generated in 0.009 seconds using 6 database queries. Style & Emoticons: "Default" by Kaloth
Icons: "Small Icons" by WendellVerli