1.Problem description
I logged the output when running the electron project, but garbled characters were displayed on the terminal, as shown in the figure:
2. Cause of the problem
This is because the Windows console uses GBK encoding by default, and our projects generally use UTF-8 encoding, so the log output to the console will produce garbled characters. We can just modify the encoding of the console.
3.Problem solving
First of all, I output the log to facilitate checking the problem during the development process, so I adopt the simplest solution. If in a production environment, the current approach may not be applicable.
This method only solves the encoding of the currently opened console. It does not modify the global encoding format. Open other consoles. The encoding is still GBK.
This method only solves the encoding of the currently opened console. It does not modify the global encoding format. Open other consoles. Console, the encoding is still GBK.
This method only solves the encoding of the currently opened console. It does not modify the global encoding format. When opening other consoles, the encoding is still GBK.
Take Idea as an example:
3.1 Open Idea’s Terminal
The console input chcp
936 corresponds to GBK encoding. We need to change it to UTF-8, which corresponds to 65001.