Solution to displaying UTF-8 characters in DOS window cmd

Source: Internet
Author: User
Tags character set

In A. SQL file that contains Chinese characters, we can see that it is UTF-8 encoded in the Eclipse attribute, as shown in the following figure,


However, when you view this file on the Windows console (for convenience, I copied the file to the desktop), it is garbled:

C: \ Users \ 002778 \ Desktop> type abc. SQL

USE Abc;

Insert into 'school 'VALUES
(1 ,'?? Bang? Too many tasks? '?? Bang ?? Juan ?? Insects ???? Too many? 7 ??, '123 ','??? Parameters ??),
(2, 'salary ??? Too many? ','?? Bang ?? Ma Feng ?? Why? Insects ?? Too many? ', '123 ','???? ?),
(3 ,'?? Bang? Too many tasks? 'Salary ??????? Bang ?? Why? Pan-fried? Bake ?? H 22 ??, '123 ','?? Nan? '),
(4, 'Juan ?? Jiehanyu? Too many? ','?? Bang ?? Ma Feng ?? Why? Insects ?? Too many? 59 ??, '123 ','??? Parameters ??),
(5 ,'??? Why does it happen? 'Success? Rainbow ????? WHY ??????? Why? 22 ??, '123 ','? Why? Response ?);

So how can we make cmd display the UTF-8 encoded characters? Here you need to know something about it:

Chcp command

Command in the chcp ms dos to display or set the active code page number. Usage:

C: \ users' \ 002778 \ Desktop> chcp /?

Displays or sets the active code page number.

CHCP [nnn]

Nnn specifies the code page number.

Enter CHCP without parameters to display the active code page number.

C: \ Users \ 002778 \ Desktop> chcp

Code page: 936

UTF8 encoding

You also need to know some coding knowledge. To support UTF8, you must at least know the UTF8 code page number: 65001. For more information about encoding, we will not go into details here. Please search for relevant content on your own.

With these two knowledge points, it is easy to support UTF8 in cmd.

1. Run cmd;

2. Enter chcp and press enter to view the current encoding;

3. Input chcp 65001 and output:

Active code page: 65001

C: \ users' \ 002778 \ Desktop>

4. If this is the case, you may still not be able to display UTF8 properly. You also need to right-click the form and select Properties to set the font. In the previous 936, there was no Lucida Console font, but after switching to 65001, we can see that:


6. Select the Lucida Console and apply it only to the current form. Confirm and try again:

In this way, the UTF8 characters are successfully displayed in cmd.


How to display UTF-8 characters in a DOS window

In the Chinese Windows system, if a file contains 8 bytes, the file content cannot be correctly displayed in the cmd.exe command line window (the so-called DOS window. By default, the code page used in the command line window is Chinese or American, that is, the code is a Chinese or Spanish character set.

If you want to correctly display UTF-8 characters, follow these steps:

1. Open the cmd.exe command line window

2. Use the chcp command to change the code page. The code page of the UTF-8 is 65001.

Chcp 65001

After this operation is performed, the code page is turned into a UTF-8. However, UTF-8 characters still cannot be correctly displayed in the window.

3. Modify window properties and font

Right-click the title bar of the command line, select "property"-> "font", change the font to "Lucida Console" of True Type, and click "OK" to apply the property to the current window.

Then you can use the type command to display the content of the UTF-8 text file:

Type filename.txt

4. The above operations cannot completely solve the problem, because the displayed content may be incomplete. The command line window can be minimized first, and the file content is displayed completely.
++

Run the command chcp:
Function:
Displays or sets the active code page number
CHCP [nnn]
Nnn specifies the code page number.
If no parameter is added, type CHCP to display the active code page number.
Nnn specifies an existing system character set, which is defined by the COUNTRY command in the CONFIG. SYS file.
In DOS, you can use the mode command to set the code page.
Selected code page: mode con [:] cp select = yyy
Code page STATUS: mode con [:] CP [/STATUS]
Press Windows + R and enter cmd or command to open the command prompt.
For example, if the input is mode con cp select = 936, the system displays simplified Chinese. If the input mode con cp select = 437, it indicates that the MS-DOS is displayed in American English, and the Chinese display will be ?.
The MS-DOS provides character sets for the following countries and languages:
Code page description
1258 Vietnamese
1257 Boro
1256 Arabic
1255 Hebrew
1254 Turkish
1253 Greek
1252 Latin 1 character (ANSI)
1251 Spanish
1250 Central European language
950 Traditional Chinese
949 Korean
936 Simplified Chinese (default)
932 Japanese
874 Thai
850 multilingual (MS-DOS Latin1)
437 MS-DOS American English


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.