Batchfile batch script garbled solution

Sometimes we may encounter garbled characters when running Batchfile

question

The bat batch processing script is as follows

1
2
3
4
5
6
@echo off

echo hello,world.
echo haha

pause

When CMD executes the script, Chinese garbled characters appear.

analyze

  1. Garbled characters are all related to character encoding. .

  2. Computers can only process numbers. If text is encountered, it must be converted to a number before processing. This is where character encodings (character sets) come in. . If you use a certain character encoding for encoding, you must use the same character encoding for decoding. If different character encodings are used, garbled characters will appear. .

solve

Convert the encoding of script files

By default, in the bat script file, if the Chinese is not ANSI encoding, garbled characters will appear. Therefore, you can use the Notepad that comes with the Windows operating system platform to open the script file, click the menu [File] - [Save As], and select ANSI encoding to save.

After converting the encoding and running it again, the Chinese garbled problem was solved.

Change code

Declare changes to the previous code in the original bat script file

1
chcp 65001

other

  1. Common code page mapping
code pagemapped character set
936GB2312
20127US-ASCII
65001UTF-8
2022-2025做了三年的事情,得到了很多收获也看到了这个世界的另一面。
Built with Hugo
Theme Stack designed by Jimmy