Thursday, July 4, 2019

[IT] Display Chinese in Command Prompt

Recently, I wanted to read some Chinese document in the Command Prompt. Unfortunately, I could not display Chinese characters by default. I learned a handy technique to do it:

chcp 936

In the Windows shell, the "code page" determines how bytes are converted to characters on the screen. Using the CHCP command changes the shell's code page. Please note that before the CHCP command can be used, the nlsfunc must be loaded and country.sys must be loaded into the config.sys.

Automation
To remove the need to do this every time, you can create a simple batch file to change the code to whatever you wish. Here, it's changed to 65001 which is Unicode. This will not be able to display East Asian characters but you will be able to type other characters.

@ECHO OFF
REM change CHCP to UTF-8
CHCP 65001
CLS

You can save this in the folder C:\Windows\System32 as a bat file such as switch.bat.

Then, create a shortcut to cmd.exe on Desktop and change the shortcut's properties to C:\Windows\System32\cmd.exe /k switch

Now whenever you need to type in a different script, you can use this shorcut.

Country and Regions
There are other codes you can use depending on what you're typing in or looking at.

Keybrd2.sys Country/Regions
274, 275 - Brazil
442 - Bulgaria
319 - Greece
161 - Iceland
118 - Macedonia, Serbia, and Montenegro
333 - Romania
441 - Russian
440, 179 - Turkish

EGA.CPI Codepages
437 - United States
850 - Multilingual (Latin I)
852 - Slavic/Eastern European
860 - Portuguese
863 - Canadian-French
865 - Nordic


EGA2.CPI Codepages
737 - Greek II
850 - Multilingual (Latin I)
852 - Slavic/Eastern European
857 - Turkish
861 - Greek

EGA3.CPI Codepages
437 - United States
850 - Multilingual (Latin I)
852 - Slavic/Eastern European
855 - Cyrillic I
866 - Russian (Cyrillic II)

References
https://www.computerhope.com/chcphlp.htm

https://www.colorconsole.de/console/en/008.htm

https://superuser.com/questions/269818/change-default-code-page-of-windows-console-to-utf-8

No comments:

Post a Comment