您的位置:首页 > 编程语言 > Python开发

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐