10

I'm working on a .bat program, and the program is written in Finnish. The problem is that CMD doesn't know these "special" letters, such as Ä, Ö, Å.

Is there a way to make those work? I'd also like it if the user could use those letters too.

Part of my code:

    @echo off
    /u
    title JustATestProgram
    goto test123

    :test123
    echo Letters : Ää Öö Åå
    pause
    exit

When I open this file, the letters look like this:

Enter image description here

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
batchguy11
  • 125
  • 1
  • 1
  • 6
  • Hi, please try to come up with a descriptive title. The primary reason for the existence of this website is to help everyone who comes after you so you need to make your question searchable. – Ben Sep 15 '13 at 14:32
  • the answer is [here](http://stackoverflow.com/questions/1259084/what-encoding-code-page-is-cmd-exe-using) – Endoro Sep 15 '13 at 18:33
  • I don't think so @Endoro; it appears as though the encoding of the editor the OP is using to create their batch file doesn't support these characters... – Ben Sep 19 '13 at 21:08
  • @Ben this might be, but probably not. I have a lot of editors here and _all_ support this. But his editors settings might be wrong. – Endoro Sep 19 '13 at 21:17

4 Answers4

19

Try putting this line at the top of the batch file:

chcp 65001

It should change the console encoding to UTF-8, and you should be able to read the file properly in the script after that.

Hari Menon
  • 33,649
  • 14
  • 85
  • 108
2

Theoretically you just need to use the /u (Unicode) switch:

c:\>cmd /u
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

c:\>echo Ä
Ä
Ben
  • 51,770
  • 36
  • 127
  • 149
  • I tried that with my test program, but it didn't work. I could show a picture (how the special letters show up) and part of the code but I cant because my reputation is not high enough. – batchguy11 Sep 15 '13 at 14:50
  • You say "open this file" @batchguy11; you're printing this out to a file? Can you echo these on your screen (no files involved)? It could easily be that the program you're using to open the file isn't configured to deal with unicode. – Ben Sep 15 '13 at 17:58
  • Yes I can print äöå on CMD but not in this .bat program for some reason. Oh and by "open this file" I mean that I made a program called test.bat and it has the code above. How do i configure the file to work with unicode – batchguy11 Sep 15 '13 at 18:07
  • No idea @batchguy11; you need to look at the help docs for whatever text editor you're using. – Ben Sep 19 '13 at 21:08
1

If you use Notepad++, you can simply change the charset. Doing this will allow you to write letters from desired charset. The western region -US. should support it.

You can do it in a drop down menu in Notepad++ or by hand by writing chcp 437. But I recommend doing this in Notepad++ as it will show you the output as it will be in the batch. So you will then easily see if you use the right code page. And at same time it's easy to switch if you want more special symbols. You can also as stated in previous posts. Try UTF-8.

You can read more about this here: http://ss64.com/nt/chcp.html. And here's a list over different code pages (check out the OEM pages): Code Page Identifiers

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
0

The command prompt uses DOS encoding. Windows uses ANSI or Unicode.

PS I'm assuming you are in the US with code page 437 rather than international English/Western European 850.

So I used Character Map to get the DOS code then find out what ANSI character that code maps to.

This is the notepad contents.

echo Ž„™”†

Which was made by putting the DOS codes for your characters into notepad.

0142, 0132, 0153, 0148, 0143, 0134 which display as the above ANSI characters.

Command prompt output

C:\Windows\system32>echo ÄäÖöÅå
ÄäÖöÅå

Alt + Character Code [Prev | Next | Contents]

Holding down alt and pressing the character code on the numeric keypad will enter that character. The keyboard language in use must support entering that character. If your keyboard supports it the code is shown on the right hand side of the status bar in Character Map else this section of the status bar is empty. The status bar us also empty for characters with well known keys, like the letters A to Z.

However there is two ways of entering codes. The point to remember here that the characters are the same for the first 127 codes. The difference is if the first number typed is a zero of not. If it is then the code will insert the character from the current character set else it will insert a character from the OEM character set. Codes over 255 enter the unicode character and are in decimal. Characters entered are converted to OEM for Dos applications and either ANSI or Unicode depending on the Windows' application. See Converting Between Decimal and Hexadecimal.

E.G., Alt + 0 then 6 then 5 then release Alt enters the letter A

From Shortcut Keys and Key Modifiers by Me at https://1drv.ms/f/s!AvqkaKIXzvDieQFjUcKneSZhDjw