python系统命令乱码如何解决
发布时间:2026-05-17 16:04:37

通过subprocess模块在windows机器上执行ping -服务器命令报告如下错误:
Ping �����Ҳ������� hostname ����������ƣ�Ȼ�����ԡ�
这里可以用python的第三发插件chardet来探测原始字符的编码
若未安装,可使用命令:
pipinstallchardet
importchardet printchardet.detect(result)
输出结果:{'confidence': 0.99, 'language': 'Chinese', 'encoding': 'GB2312'}
condidence:表示正确的猜测概率
检测结果后,用decode解密:
result.decode('GB2312')结果如下:Ping 请求找不到主机 hostname。请检查这个名字,然后重试。
请关注Python视频教程栏目,了解更多Python知识。
下一篇 返回列表
