Originally published on: Wed, 19 May 2010 00:45:10 +0000
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
Save to del.icio.us
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 |
Subscribe!
Auto Save Clipboard Images Redux
Extending SpiderMonkey JavaScript on Windows
Rhino JavaScript to EXE with launch4j
Compiling Rhino JavaScript to Java
Directory Traversal in Rhino JavaScript
A Command-Line MP3 Player for Windows
Auto Save Images from the Clipboard
Java in a Windows EXE with launch4j
An Interview with Tom Zimmer: Forth System Developer
Setting Windows Console Text Colors in C
Internet Protocols and Rhino JavaScript
Hiding Batch File Console Windows
Extracting URL Addresses from Text in C
Shrouding CSharp and Java Source Code with AWK
A Simple Media Control Interface Script Processor
Jim Butterfield : The Commodore Guru
Directory Traversal in Rhino JavaScript
MicroISV on a Shoestring
DadHacker
The Bottom Feeder
Writin' That Code!
The Recursive ISV
The Thomsen Blog
Prototypically Speaking
The Reinvigorated Programmer