Computing.Net > Forums > Programming > ANSI Codes

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

ANSI Codes

Reply to Message Icon

Name: keridbey
Date: January 10, 2008 at 08:18:08 Pacific
OS: WinXP
CPU/Ram: 1.83 Ghz / 1 Gb
Product: Dell
Comment:

I'm trying to include some ANSI codes into a batch file to add a little color. I've noticed that ANSI.SYS isn't loaded by default in WinXP, but even when I do add DEVICE=ANSI.SYS to my C:\WINDOWS\system32\config.nt file and reboot, it doesn't recognize the codes (just displays them as plain text). I have a copy of ANSI.COM as well, but it doesn't recognize them, either. I made the Escape character in Edit (Ctrl-P, then Escape). Am I doing something wrong, or is WinXP just not friendly to ANSI codes?

Here's an example:

echo Hello World!

The box is the Escape code, of course. The docs I read on this indicate that this should clear the screen, move the cursor, then display the text with a white foreground and a blue background.




Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: January 10, 2008 at 08:35:38 Pacific
Reply:

You can't enable ANSI escape codes in Windows XP because it is a NT kernel based system, while ANSI.SYS requires a DOS core and command.com interpreter (cmd.exe in WinXP) as Windows 9X/ME or legacy DOS/Win 3X systems.

So forget escape codes, but you can achieve a bit of colour by using the color command.
To get what you want code

color 1F

See color /? for other choices.



0

Response Number 2
Name: klint
Date: January 10, 2008 at 08:57:15 Pacific
Reply:

You can only use ANSI.SYS in the COMMAND.COM interpreter, which is included in Windows for compatibility with old MS-DOS applications, and runs in the 16-bit Virtual DOS Machine.

Run COMMAND.COM if you really must, but note that it runs slower than CMD.exe (the native 32-bit Windows command interpreter), and contains many restrictions such as not supporting long file names or any of the newer batch commands.


0

Response Number 3
Name: keridbey
Date: January 10, 2008 at 15:40:24 Pacific
Reply:

Argh... I was afraid you'd say that. That's a shame. Ah well, the COLOR command is the way I'll go, then. Thanks!!!


0

Response Number 4
Name: User123456789
Date: January 11, 2008 at 01:21:19 Pacific
Reply:

I've always wondered how you have to use colored text in a DOS window under WinXP and such. The COLOR command sets the whole box in different fore- and/or backgroundcolor.

... but no line or string of text ?

Do I have to get my ancient C-compiler again ?

Hi there.


0

Response Number 5
Name: IVO
Date: January 11, 2008 at 02:43:20 Pacific
Reply:

For mixed color strings put your ancient C compiler ready to fly.


0

Related Posts

See More



Response Number 6
Name: User123456789
Date: January 11, 2008 at 06:03:13 Pacific
Reply:

OK.


Boooorlaaaaaaand, where are you ?

Hi there.


0

Response Number 7
Name: klint
Date: January 11, 2008 at 07:30:25 Pacific
Reply:

What programming language do you use at the moment, if you've given up C? If you're after something modern, you can use the win32api package from Python for Windows Extensions.


0

Response Number 8
Name: keridbey
Date: January 12, 2008 at 11:35:14 Pacific
Reply:

Just because I was curious if I could get it to work, I decided to try using the COMMAND.COM to utilize ANSI.SYS. It worked! Here's what I did (just for information's sake):

1. Created a new file - C:\WINDOWS\system32\ANSI.NT
2. Saved the new file with these contents:
dosonly
device=%systemroot%\system32\ansi.sys
device=%SystemRoot%\system32\himem.sys
files=40
dos=high,umb
3. Created a shortcut to C:\WINDOWS\system32\COMMAND.COM
4. Right-clicked the shortcut, selected Properties, and clicked the Advanced button on the Program tab.
5. Changed the "Config filename" field to point at my new ANSI.NT file (I left the "Autoexec filename" field the way it was)
6. Used that shortcut to open COMMAND.COM, used EDIT to create a test .BAT file (since .CMD files don't work in COMMAND.COM) that included some ANSI codes (I'm not sure of any other way to create escape code characters, except maybe copying and pasting them from pre-existing files).
7. When I then ran the batch file, it recognized all the codes I put in there.

I may try to figure out a way to call COMMAND.COM with the new ANSI.NT from a standard .CMD file and see how that goes.

Thanks for your help, everyone!


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: ANSI Codes

masked input www.computing.net/answers/programming/masked-input/9894.html

Function Keys in DOS www.computing.net/answers/programming/function-keys-in-dos/1194.html

printing out quotes around a string www.computing.net/answers/programming/printing-out-quotes-around-a-string/5886.html