subprocess之check_out用法
在python3中使用subprocess的check_out方法时,因为该输出为byte类型,所以如果要查看具体的内容时需要进行转码,如果转码不对话,会影响内容输出的可读性,如下: #1,输出解码不带参数 1 # -*- coding:utf-8 -*- 2 3 import subprocess 4 cmd = r"ping www.baidu.com" 5 result = subprocess.check_output(cmd) 6 print(result.decode()) # decode中不带参数,默认是以utf-8解码 7 8 9 输出报错: 10 Traceback (most recent call last): 11 File "E:/debug.py", line 12, in <module> 12 print(result.decode()) # decode中不带参数 13 UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd5 in position 2: invalid continuation byte 14 15 Process finished with exit code 1 #2,输出解码带上 unicode_escape 参数,会显示乱码 1 # -*- coding:utf