Python uses the subprocess module to easily run system commands, and to get input, but when the output of the content of Chinese when the returned data is encoded, not normal display, so it is necessary to transcode, the process is as follows:
First of all, you should know the command to use which encoding to display the output results, run the chcp command on the command line to get the active page code, such as: "active page code: 936"
MS-DOS provides character sets for the following countries and languages:
Code page description
1258 Vietnamese
1257 the Baltic language
1256 Arabic
1255 Hebrew
1254 Turkish
1253 Greek
1252 Latin 1 characters (ANSI)
1251 Cyrillic language
1250 Central European languages
950 Traditional Chinese
949 Korean
936 Simplified Chinese (default) GBK
932 Japanese
874 Thai
850 Multi-lingual (MS-DOS Latin1)
437 MS-DOS American English
65001 UTF-8
In the PY, the obtained results can be transcoded accordingly.
For example, my Activity code page is 936, which is GBK encoding
Then it should be written like this:
String = str (Output.stdout.readline (), encoding='gbk')
Output returns an object for the Subprocess.popen command
Python uses subprocess to get command line input after Chinese transcoding problem