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

>Python下使用subprocess中文乱码的解决方案

2015-04-04 21:13 681 查看
# -*- coding: CP936 -*-

import subprocess


cmd="cmd.exe"

begin=101

end=110

while begin<end:

#reload(sys)

#sys.setdefaultencoding('CP936')

p=subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE,stdin=subprocess.PIPE,stderr=subprocess.PIPE)

p.stdin.write("echo 你好."+str(begin)+"\n")

p.stdin.close()

p.wait()

print "excution result:\n"

pout=''.join(p.stdout.readlines())

output=pout.decode('cp936').encode('utf-8')

print "%s\n" % output

begin=begin+1

[/code]

来自为知笔记(Wiz)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: