Originally published on: Wed, 19 May 2010 00:45:10 +0000
Please note! If you're having difficulties compiling the C source code presented below, please see my post: Compiling C from the Command Line with Pelles C
From the comments section of my post Setting Text Color in a Batch File:
Agreed. This is a great little program. However, I would love a corresponding 'getcolor.exe' program to return the current colors.
The problem is my scripts are run by different users who may not be running with the default background and foreground colors. Plus, if I had a 'getcolor' ability, I could do reverse video and bold and they would work regardless of the current colors.
I could hopefully grab your source code and do this myself but if you wanted to take a stab at it first, I'd be happy to have you do it
I didn't initially have much of a narrative for this one, but I ran into interesting opportunities when trying to run the code.
The utility is called getcolor You must supply at least one command-line parameter. If the parameter is -f, the foreground color attribute will be written to the standard output device in hexadecimal notation.
If the parameter is -b, the background color attribute will be written to stdout in hex.
You may supply a second parameter that should represent an output text filename where the attribute will alternately be written. Initially, I had tried redirecting the output to a file, but the attributes returned were then no longer reflecting the current console buffer, since stdout was being redirected. I saw some weird results.
Here's a batch file that demonstrates how to obtain the foreground and background colors in two separate environmental variables.
getcolor.c
The source code and executable file for getcolor can be downloaded from a single archive at: http://www.mailsend-online.com/wp/getcolor.zip
Unless otherwise noted, all code and text entries are Copyright ©2010 by James K. Lawless
Views expressed in this blog are those of the author and do not necessary reflect those of the author's employer. Views expressed in the comments are those of the responding individual.

Save to StumbleUpon
Digg it
Save to Reddit
Share on Facebook
Share on Twitter
More bookmarks
| Previous post: | An Interview with the Author of the French Silk Assembler |
|---|---|
| Next post: | Computers I Have Known |
Click **here**
A JavaScript REPL for Android Devices
A Review of Kevin Mitnick's Book Ghost in the Wires
Play MP3 Files with Python on Windows
Understanding TRS-80 CMD Files
Changing the C64 Text Color in C
Java in a Windows EXE with launch4j
A Review of Kevin Mitnick's Book Ghost in the Wires
Hiding Batch File Console Windows
Why Some Web Sites will go Dark on Jan 18th
Book Review : Paull Allen - Idea Man
A 90's Experiment in Online Systems - The U.S. West CommunityLink Service