Two lines of commands to fix powershell utf-8 garbled characters

Powershell does not support utf-8 encoding, and the output is garbled?

Two lines fix this problem

The first line: open powershell input

notepad $PROFILE

Install vscode and knock the following

code $PROFILE

In the opened file enter

[System.Console]::OutputEncoding = [System.Console]::InputEncoding = [System.Text.Encoding]::UTF8

Well, just reopen a powershell.

Briefly explain:

In powershell, you can no longer use chcp 65001, which was originally suitable for cmd, to solve the problem of utf-8 encoding. If you search for chcp 65001, it will not work, because it can only be used by cmd.

The second line of code above means to change the output encoding and input encoding of System.Console to system text file encoding and UTF-8, that is, to support both. If you do not want to take effect every time, it is also possible to directly execute the second line.

The first line is to use notepad or vscode to open the powershell default configuration file. The content in this configuration file will be executed automatically every time powershell starts. If you want to know exactly where it is, just enter $PROFILE and press Enter.

Guess you like

Origin blog.csdn.net/baijiafan/article/details/131599018