Using non-ASCII characters in cmd batch file

I am working on a .bat program and the program is written in Finnish. The problem is that CMD does not know these “special” letters, such as Ä, Ö, Å.

Is there any way to make them work? I would also like it if the user could use these 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

+4
source share
4 answers

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

 chcp 65001 

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

+5
source

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

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

If you use Notepad ++, you can just change the encoding. This will allow you to write letters from the desired encoding. Western region - USA. must support him.

You can do this in the drop-down menu in Notepad ++ or manually by writing chcp 437. But I recommend doing this in Notepad ++, as it will show you the result as it will be in the package. This way you can easily see if you are using the correct code page. And at the same time, it's easy to switch if you want more special characters. You can also, as indicated in previous posts. Try UTF-8.

You can find out more about this here: http://ss64.com/nt/chcp.html . And here is a list on different code pages (check OEM pages): Code page identifiers

+1
source

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

PS I assume that you are in the USA with code page 437, and not with international English / West European 850.

So, I used a character map to get the DOS code, and then find out which ANSI character matches the code.

This is the content of the notebook.

 echo Ž„™"† 

This was done by putting DOS codes for your characters in a notepad.

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

Command line output

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

Alt + character code [Prev | Next | Content]

Holding down the alt key and pressing the character code on the numeric keypad enters that character. The keyboard language used must support this character input. If your keyboard supports it, the code is displayed on the right side of the status bar in the character map, otherwise this section of the status bar is empty. The status bar is also empty for characters with well-known keys, such as letters A to Z.

However, there are two ways to enter codes. It should be remembered that the characters are the same for the first 127 codes. The difference is that the first number entered is zero. If so, then the code will insert a character from the current character set, otherwise it will insert a character from the OEM character set. Codes over 255 enter the Unicode character and are in decimal form. Entered characters are converted to OEM for Dos and ANSI or Unicode applications depending on the Windows application. See Convert Between Decimal and Hexadecimal.

EG, Alt + 0, then 6, then 5, then release Alt by entering the letter A

From keyboard shortcuts and key modifiers to Me https://1drv.ms/f/s!AvqkaKIXzvDieQFjUcKneSZhDjw

0
source

Source: https://habr.com/ru/post/1502272/


All Articles