Python下使用subprocess中文乱码的解决方案
2017-08-01 10:17
441 查看
分类:python http://blog.sina.com.cn/s/blog_567002510101c516.html http://www.cnblogs.com/bsmagic/p/4392928.html 1、window上使用shell显示中文
reload(sys) sys.setdefaultencoding('utf-8')
2、cybiwn pycharm 中显示中文
output = line.decode('cp936').encode('utf-8')print "%s\n" % output
import subprocessimport syscmd = "cmd.exe"begin = 101end = 102while begin < end:##blow for windows shell chinese show###reload(sys)#sys.setdefaultencoding('utf-8')print "excution result start :\n"child = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE)print "ping -n 1 -w 100 192.168.1." + str(begin) + "\n"child.stdin.write("ping -n 1 -w 100 192.168.1." + str(begin) + "\n")child.stdin.close()child.wait()print "excution result end:\n"begin += 1#print child.stdout.readlines()for line in child.stdout.readlines():##blow for pycharm and cygwin show chinese#output = line.decode('cp936').encode('utf-8')print "%s\n" % output
相关文章推荐
- Python下使用subprocess中文乱码的解决方案
- >Python下使用subprocess中文乱码的解决方案
- selenium使用python的csv进行参数化时,中文乱码解决方案
- Latex中使用dvipdfm转换方式hyperref包生成PDF中文书签乱码的解决方案
- Python的Print打印中文乱码解决方案
- 使用JSP开发应用程序时的编码(中文等乱码)问题的建议解决方案(包括接受request和数据库操作)
- Python用cx_Oracle链接Oracle数据库中文乱码解决方案
- 使用struts2+spring+tomcat+mysql数据库开发中文乱码问题解决方案
- 关于使用jsp时出现中文乱码的解决方案总结
- 【可行】windows下使用vim显示中文乱码的解决方案
- 使用source命令向数据库写入数据中文乱码的解决方案
- Python 2 中文乱码解决方案:
- [Note]关于Python中文编码出现乱码的解决方案(涉及urllib.urlopen(),open()等函数)
- 使用JSP开发应用程序时的编码(中文等乱码)问题的建议解决方案(包括接受request和数据库操作)
- IE7、IE8下使用escape、encodeURI传递中文参数乱码的问题及解决方案
- Python 中使用 ogr 生成 shape 文件时的中文乱码问题
- Linux下如何解压rar、zip格式文件?Linux VPS安装7zip/使用方法/压缩解压中文文件名乱码解决方案
- Fedora 14使用问题(一)-audacious的安装 和 Rhythmbox中文乱码解决方案
- java(jsp)使用MySql数据库,中文乱码的完整解决方案
- MFC使用webbrowser时navigate的url中有中文字符,在php服务器端取得的是乱码问题的解决方案