问题
So I have a batch file tool that is originally in English, and I am having translated to various other languages. My situation is that many languages use special characters. In my case, it is German.
So I might have in the English one:
echo Administrative permissions required. Detecting permissions...
Then in the German one, I\'d have:
Administratorrechte benötigt. Überprüfe Berechtigungen...
Which uses different types of characters. Now, in my research, I have found the windows command chcp
for changing code pages. Now, what I\'m trying to do, is change the code page (or any other way of doing this) to allow for these characters to display. My current code page is the one for US English; 437
. For German, I believe I need to use 1141
(source). I have read that you can do things like changing the CMD settings, or making more permanent changes via the registry. But I need this to be on demand when a random person runs this file, with minimal effort.
I have tried setting the code page to 1141
by adding chcp 1141
at the start of the batch file, but this causes errors. The batch file cannot understand my commands anymore.
回答1:
Windows with a German country configured in Windows region and language settings use OEM code page 850 which is very similar to OEM code page 437. The characters ÄÖÜäöüß
have same binary value in both code pages.
Usage of UTF-8 encoding with no BOM (code page 65001) is unfortunately no real option on Windows prior Windows 8 as the default console font is raster font Terminal not supporting Unicode.
A batch file encoded in UTF-8 with no byte order mark with the command lines
@echo off
%SystemRoot%\System32\chcp.com 65001 >nul
echo Es werden Administratorrechte benötigt. Überprüfe Berechtigungen ...
results either in nothing output on Windows XP or on Windows Vista and Windows 7 in getting just displayed the error message:
The system cannot write to the specified device.
The UTF-8 encoded batch file works on Windows 8 / 8.1 / 10 which uses by default the font Consolas supporting Unicode. Thanks eryksun for this additional information.
来源:https://stackoverflow.com/questions/48981387/using-another-language-code-page-in-a-batch-file-made-for-others