Link to home
Create AccountLog in
Avatar of Stef Merlijn
Stef MerlijnFlag for Netherlands

asked on

Batchfile: How to use ANSI in echo

Hi,

I want to show some output in my batchfile (ECHO).
The strings however contain some characters like:  ëüö
These characters aren't displayed correctly by default.

Following code should make this work, but it doesn't seem to work under Windows 7 x64

Any ideas?
for /f "tokens=*" %%i in ('chcp') do set oldchcp=%%i
set oldchcp=%oldchcp:Aktive Codepage: =%
set oldchcp=%oldchcp:.=%
chcp 1250>NUL
REM YOUR STUFF WITH öäööäöü etc.
chcp %oldchcp%>NUL

Open in new window

Avatar of s_chilkury
s_chilkury
Flag of United States of America image

If you save batch script in ANSI format, characters like ëüö are not displayed correctly!!!

Save your batch script in DOS format and you will get these characters correctly.

You can use DOS editor edit.com to save your batch scripts automatically in the right format.

You can also use modern editors like notepad++ or UltraEdit
http://notepad-plus.en.softonic.com/

To save your batch script with these editors in the correct format, you have to choose OEM charset coding...

Avatar of Stef Merlijn

ASKER

s_chilkury:
Can you supply me with a simple example?
f.e. a Batchfile that shows a message containing: "ëüö"
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Hi,

I tried to do some little test, but the output is not as expected (see image).
@echo off
setlocal
if /i "%~1"=="/truetype" (shift&title Command Prompt&goto Begin)
set Identifier=TrueType
reg add "HKCU\Console\%Identifier%" /v "FaceName"   /t REG_SZ    /d "Lucida Console" /f >NUL 2>&1
reg add "HKCU\Console\%Identifier%" /v "FontFamily" /t REG_DWORD /d "0x00000036"     /f >NUL 2>&1
reg add "HKCU\Console\%Identifier%" /v "FontSize"   /t REG_DWORD /d "0x000e0000"     /f >NUL 2>&1
reg add "HKCU\Console\%Identifier%" /v "FontWeight" /t REG_DWORD /d "0x00000190"     /f >NUL 2>&1
REM replace /c in the following line with /k to leave the command prompt open after the script finishes.
start "%Identifier%" "%ComSpec%" /c "%~0 /truetype %*"
REM Remove the REM in front of the following 'exit' to close the original command prompt.

:BEGIN
echo First command line argument: %1
chcp
echo Çüéâäàåçêëèïî
chcp 1250
echo Çüéâäàåçêëèïî
chcp 1252
echo Çüéâäàåçêëèïî

Pause
Exit

Open in new window

Font-in-Batchfile.jpg
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Two test scripts for you with different codings, to see that it works with the right editor and coding...
test-ANSI.cmd
Test-OEM.cmd
Thank you very much.