Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ANSI Colored text in CMD

1,570 views
Skip to first unread message

est

unread,
May 4, 2007, 7:55:17 AM5/4/07
to
Just finished this:

@echo off
chcp 437>nul&&graftabl 936>nul
ren %WinDir%\System32\config.nt %WinDir%\System32\config.nt.bak 2>nul
<"%~f0" more +7 >%WinDir%\System32\config.nt
echo DEVICE=%WinDir%\System32\ANSI.SYS /x >>%WinDir%
\System32\config.nt
command /cecho [1;31mele [32mct [33mroni [35mX [36mtar [m
pause>nul&exit
DOSONLY
dos=high, umb
device=%SystemRoot%\system32\himem.sys
files=40

If you could not see the effect please reply with your %WinDir%
\System32\Config.nt file content. Thank you.

est

unread,
May 4, 2007, 8:07:14 AM5/4/07
to

Oops, I think there is some special charactor missing. Here in this
line:

command /cecho [1;31mele [32mct [33mroni [35mX [36mtar [m

There should be a ESC charactor befor each [
You can type it by tap 2 and 7 in numpad while pressing ALT

Timo Salmi

unread,
May 4, 2007, 3:33:37 PM5/4/07
to
est <electr...@gmail.com> wrote:
> Just finished this:
:

> echo DEVICE=%WinDir%\System32\ANSI.SYS /x >>%WinDir%
> \System32\config.nt
> command /cecho [1;31mele [32mct [33mroni [35mX [36mtar [m
:

Inventive. Well done. The first time I've seen ANSI.SYS work in XP.

All the best, Timo

--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance ; University of Vaasa
mailto:t...@uwasa.fi <http://www.uwasa.fi/~ts/> ; FIN-65101, Finland
Useful script files and tricks ftp://garbo.uwasa.fi/pc/link/tscmd.zip

tw

unread,
May 4, 2007, 4:37:12 PM5/4/07
to
On May 4, 4:55 am, est <electronix...@gmail.com> wrote:
> Just finished this:
>

> ren %WinDir%\System32\config.nt %WinDir%\System32\config.nt.bak 2>nul

Very cool.

You should be careful about this particular line. The syntax is
incorrect and a backup of config.nt is not accomplished. It would
need to read something like this:

ren %WinDir%\System32\config.nt config.nt.bak
if errorlevel 1 goto :eof

Cheers,
Tom

est

unread,
May 4, 2007, 11:43:33 PM5/4/07
to

Thanks for the advice.

Let me explain this line:


chcp 437>nul&&graftabl 936>nul

Which means to let Chinese charactors display normally in CMD

Some people report that the can only run this batch script ONCE I
don't know why. Anybody have any idea?

Timo Salmi

unread,
May 5, 2007, 1:42:57 AM5/5/07
to
Timo Salmi <t...@uwasa.fi> wrote:
> est <electr...@gmail.com> wrote:
(snip, the method)

> Inventive. Well done. The first time I've seen ANSI.SYS work in XP.

I am adding something like this to the FAQ item
51} How can I echo lines in different colors in NT scripts?

DRAFT:

However, there is, after all, a clever trick to get the ANSI.SYS
color codes in XP based on a posting in alt.msdos.batch.nt

@echo off & setlocal enableextensions
::
:: The paths
set ConfigNT=%WinDir%\System32\config.nt
set ConfigNTbak=%WinDir%\System32\config.nt.bak
::
:: Check that you have a backup or your original CONGIF.NT
if not exist "%ConfigNTbak%" (
echo.
echo Exiting %~f0
echo "%ConfigNTbak%"
echo File not found. Needed for restoring config.nt so first run
echo copy "%ConfigNT%" "%ConfigNTbak%"
goto :EOF
)
::
:: Use a copy of the backup as a double safety
copy "%ConfigNTbak%" "%temp%\CONFIG.NT">nul
::
:: Customize CONFIG.NT to use ANSI.SYS
> "%ConfigNT%" echo DOSONLY
>>"%ConfigNT%" echo dos=high, umb
>>"%ConfigNT%" echo device=%%SystemRoot%%\system32\himem.sys
>>"%ConfigNT%" echo files=40
>>"%ConfigNT%" echo DEVICE=%WinDir%\System32\ANSI.SYS /x
::
:: Choose the MS-DOS color
command /cecho <ESC char 27>[0;40;31;1mANSI.SYS turn on
::
:: Restore the original CONFIG.NT
copy "%temp%\CONFIG.NT" "%WinDir%\System32\">nul
if exist "%temp%\CONFIG.NT" del "%temp%\CONFIG.NT">nul
endlocal & goto :EOF

After running the above script in the CMD.EXE ANSI escape sequences
can be used in the other scripts applying the following format of
the echo
command /cecho TheAnsiSequence

The advantage of this method over using an external program such as
my ECHOC.EXE to output in colors is that it is faster. The
disadvantage is that if you have a CMD shortcut to open and
customize your preferred CLI Window, the method will not work
(because of the reasons explained in the documentation of CONFIG.NT
in the comment about CONFIG.SYS vs CONFIG.NT.)

References/Comments:
http://www.google.com/groups?selm=bts0me$e7b%40poiju.uwasa.fi
http://www.google.com/groups?selm=40F2CE8D.98194BFA%40yahoo.com.au

http://www.google.com/groups?selm=1178279717.580298.7190%40n76g2000hsh.googlegroups.com

est

unread,
May 5, 2007, 1:19:09 PM5/5/07
to
On May 5, 1:42 pm, Timo Salmi <t...@uwasa.fi> wrote:
> Timo Salmi <t...@uwasa.fi> wrote:
> http://www.google.com/groups?selm=1178279717.580298.7190%40n76g2000hs...

>
> All the best, Timo
>
> --
> Prof. Timo Salmi ftp &http://garbo.uwasa.fi/archives 193.166.120.5

> Department of Accounting and Business Finance ; University of Vaasa
> mailto:t...@uwasa.fi <http://www.uwasa.fi/~ts/> ; FIN-65101, Finland
> Useful script files and tricksftp://garbo.uwasa.fi/pc/link/tscmd.zip

That's cool.

BTW, is there a tool that can convert BMP/JPG/GIF images to ANSI
escaped texts? Or convert to an rtf ?(rtf meets the ANSI color
standard, too)

Timo Salmi

unread,
May 6, 2007, 2:54:01 AM5/6/07
to
Timo Salmi <t...@uwasa.fi> wrote:
> I am adding something like this to the FAQ item
> 51} How can I echo lines in different colors in NT scripts?

After running the config.nt trick in the previous posts one should have
ANSI loaded. To test

:: Check if loading ANSI was successful
mem /c | find /i " ansi ">nul
if %errorlevel% GTR 0 (
echo.
echo Warning: ANSI not loaded
)

A demonstration with ANSI producted colors
@echo off & setlocal enableextensions enabledelayedexpansion
cls
set cecho_=command /cecho
for /l %%i in (0,1,7) do (
for /l %%j in (2,1,9) do (
set /a k=%%j-2
%cecho_% <ESC>[%%j;%%i1H<ESC>[4!k!;3%%im[4!k!;3%%i;1m
)
)
%cecho_% <ESC>[40;30;1mThe end of the demo by Prof. Timo Salmi
endlocal & goto :EOF

Harlan Grove

unread,
May 7, 2007, 1:08:00 PM5/7/07
to
Timo Salmi <t...@uwasa.fi> wrote...
...

>However, there is, after all, a clever trick to get the ANSI.SYS
>color codes in XP based on a posting in alt.msdos.batch.nt
...

While it's clever, it has a few drawbacks. COMMAND seems only to be
able to handle a few VGA console sizes: 25, 43 and 50 lines, all by 80
characters wide. If the CMD console window layout is anything other
than this, running COMMAND fubars it. I doubt the other ANSI escape
sequences work properly.

Timo Salmi

unread,
May 7, 2007, 3:22:26 PM5/7/07
to
Harlan Grove <hrl...@gmail.com> wrote:
> Timo Salmi <t...@uwasa.fi> wrote... ...
>> However, there is, after all, a clever trick to get the ANSI.SYS
>> color codes in XP based on a posting in alt.msdos.batch.nt

> While it's clever, it has a few drawbacks. COMMAND seems only to be

> able to handle a few VGA console sizes: 25, 43 and 50 lines, all by
> 80 characters wide. If the CMD console window layout is anything
> other than this, running COMMAND fubars it.

Probably so, but what else than MS-DOS emulation would and should one
really expect and require in the first place? Many MS-DOS programs run
in a CMD box have such natural limitations. Desktop-level graphics
hardly are the goal in this, Harlan.

> I doubt the other ANSI escape sequences work properly.

That's up to testing. Haven't tested key substitution. However, at least
the cursor positioning ANSI sequences seem to work on top of the color
codes.

Harlan Grove

unread,
May 7, 2007, 6:12:12 PM5/7/07
to
Timo Salmi <t...@uwasa.fi> wrote...
...
>Probably so, but what else than MS-DOS emulation would and should one
>really expect and require in the first place? Many MS-DOS programs run
>in a CMD box have such natural limitations. Desktop-level graphics
>hardly are the goal in this, Harlan.

Where did I mention graphics? What I mentioned is that COMMAND seems
to work only with screen sizes (in terms of character positions) of 80
columns by 25, 43 or 50 rows and *changes the layouts other than that
when run from CMD. Some of use use CMD windows with more than 80
columns.

As for MS-DOS programs and their limitations, isn't that a subject for
alt.msdos.batch rather than this ng? Myself, I don't use any, but FWIW
the FAR file manager works just fine (using the whole console window)
in 132 columns by 50 line layout. Not all character mode programs are
legacy MS-DOS programs.

Methinks you want to gloss over the unfortunate fact that COMMAND
could screw up CMD console window layouts. I'll wait to see whether
you mention this or not in your faq.

>>I doubt the other ANSI escape sequences work properly.
>
>That's up to testing. Haven't tested key substitution. However, at least
>the cursor positioning ANSI sequences seem to work on top of the color
>codes.

Cursor positioning should work within 80-by-{25,43,50} COMMAND
windows. Key substritutions could only work within COMMAND sessions,
so unless COMMAND remained as the command processor during input, it
effectively doesn't work.

Timo Salmi

unread,
May 8, 2007, 12:39:24 AM5/8/07
to
Harlan Grove <hrl...@gmail.com> wrote:
> Timo Salmi <t...@uwasa.fi> wrote...
>> Probably so, but what else than MS-DOS emulation would and should
>> one really expect and require in the first place?

(As such sensible counterpoints and refutals snipped.)

I fear we might be slipping into arguing the obvious, which makes me
skittish.

> Methinks you want to gloss over the unfortunate fact that COMMAND
> could screw up CMD console window layouts. I'll wait to see whether
> you mention this or not in your faq.

No, Harlan, I probably won't mention that strange speculation of yours
about my frame of mind.

Timo Salmi

unread,
May 8, 2007, 4:05:13 AM5/8/07
to
Timo Salmi <t...@uwasa.fi> wrote:

> Harlan Grove <hrl...@gmail.com> wrote:
>> Methinks you want to gloss over the unfortunate fact that COMMAND
>> could screw up CMD console window layouts. I'll wait to see whether
>> you mention this or not in your faq.

> No, Harlan, I probably won't mention that strange speculation of
> yours about my frame of mind.

I though I was fluent in English, but obviously I am not. I misread the
"gloss over". Yes, I'll mention that there are limitations to the screen
modes.

All the best, Timo

--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance ; University of Vaasa
mailto:t...@uwasa.fi <http://www.uwasa.fi/~ts/> ; FIN-65101, Finland

Timo's FAQ materials at http://www.uwasa.fi/~ts/http/tsfaq.html

Timo Salmi

unread,
May 8, 2007, 11:09:38 AM5/8/07
to
Harlan Grove <hrl...@gmail.com> wrote:
> Timo Salmi <t...@uwasa.fi> wrote...

>> [Eearlier I wrote] Many MS-DOS programs run in a CMD box have such
>> natural limitations.

> As for MS-DOS programs and their limitations, isn't that a subject

> for alt.msdos.batch rather than this ng?

That left me baffled. Do you mean I should have crossposted my note to
alt.msdos.batch because I mentioned what an MS-DOS program can cause in
the CMD.EXE (which is not native in alt.msdos.batch related systems)
CLI. Or should I have divided that statement right in the middle into
two parts, posted the first part into alt.msdos.batch and the latter to
alt.msdos.batch.nt, or what?

> Myself, I don't use any, but FWIW

Please enlighten me. What does FWIW mean?

> the FAR file manager works

Please further enlighten me. What is FAR file manager?

> just fine (using the whole console window) in 132 columns by 50 line
> layout. Not all character mode programs are legacy MS-DOS programs.

> Methinks you want to gloss over

Ok, I looked it up in a dictionary (gloss over = to cover up something)
since I first mistook it for "gloat over" and responded accordingly.

> the unfortunate fact that COMMAND could screw up CMD console window
> layouts.

The FAQ item in question (#51) does not pressure anyone to use the
method. Furthermore, it only is the second option presented for getting
colors. A cover up? Some solution is better than none. Who claimed it
was perfect?

As for more English, as a non-native I read "screw up" as damage, right
or wrong. Seems doubtful. The method might not work in each and every
respect as one wishes, but I don't get what the actual harm is that it
is supposed to cause. But if there is such a potential damage, it would
indeed be good to know about it.

> I'll wait to see whether you mention this or not in your faq.

>>> I doubt the other ANSI escape sequences work properly.
>> That's up to testing. Haven't tested key substitution. However, at
>> least the cursor positioning ANSI sequences seem to work on top of
>> the color codes.

> Cursor positioning should work within 80-by-{25,43,50} COMMAND
> windows.

It also works with CMD.EXE CLI with ANSI.SYS loaded as presented in the
draft addendum to the FAQ item #51.

> Key substritutions could only work within COMMAND sessions, so unless
> COMMAND remained as the command processor during input, it
> effectively doesn't work.

Right. Quite likely it is so. The item, anyway, is about getting colors,
not about key substition.

Harlan, I am still left wondering why you might have felt fairly stronly
about this particular addition to the CLI script lore and my posting it.
Or perhaps I just misread you. Thanks for the views, anyway. Always
useful.

Todd Vargo

unread,
May 8, 2007, 11:55:50 AM5/8/07
to
"Timo Salmi" <t...@uwasa.fi> wrote:
> Please enlighten me. What does FWIW mean?

For What It's Worth.

>
> > the FAR file manager works
>
> Please further enlighten me. What is FAR file manager?

http://www.farmanager.com/

I suppose it's functionally similar to DOSSHELL.

--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)

Message has been deleted

Timo Salmi

unread,
May 8, 2007, 2:15:03 PM5/8/07
to
Todd Vargo <tlv...@sbcglobal.netz> wrote:
> "Timo Salmi" <t...@uwasa.fi> wrote:
>> Please further enlighten me. What is FAR file manager?
> http://www.farmanager.com/
> I suppose it's functionally similar to DOSSHELL.

Thanks, Todd. At a quick glance seems slightly far fetched in the
context of ANSI colors. Not that it might be even very useful, but the
first time I've heard of it, so perhaps not the most frequent of tools?

Message has been deleted

Harlan Grove

unread,
May 8, 2007, 3:04:39 PM5/8/07
to
Timo Salmi <t...@uwasa.fi> wrote...
...
>Thanks, Todd. At a quick glance seems slightly far fetched in the
>context of ANSI colors. Not that it might be even very useful, but the
>first time I've heard of it, so perhaps not the most frequent of tools?

It was meant as an example of a full-screen Win32-specific console/
character mode applications which can adapt themselves to whatever the
particular console window layout happens to be. This was in response
to your implication that there are few console mode applications using
other than standard MS-DOS screen sizes.

As for infrequently used tools, doesn't that apply to anything &
everything discussed in this ng since batch files are very seldom used
any more except by a very small minority of Windows users and the even
smaller number (though undoubtedly a higher percentage) of MS-DOS
users?

Matthias Tacke

unread,
May 8, 2007, 3:14:46 PM5/8/07
to
Timo Salmi wrote:
> Thanks, Todd. At a quick glance seems slightly far fetched in the
> context of ANSI colors. Not that it might be even very useful, but the
> first time I've heard of it, so perhaps not the most frequent of tools?
>

Not that it counts, but I'm an every day user of Far and it's a great program.

--
Greetings
Matthias

Mark Blain

unread,
May 8, 2007, 5:48:57 PM5/8/07
to
est <electr...@gmail.com> wrote in news:1178279717.580298.7190
@n76g2000hsh.googlegroups.com:

Very slick. An that's coming from someone who was once stubborn
(insane?) enough to install a telnet server on his own computer and then
telnet to "localhost" with Hyperterminal in VT100 mode, just to view an
old file containing ANSI control codes!

On a related note, I recently read about a program similar to ANSI.SYS
but designed to run in CMD.EXE, called ANSICON:
http://www.geocities.com/jadoxa/
I haven't tested it because it's overkill for my scripting needs, but it
might be fun to try.

0 new messages