Python下使用subprocess中文乱码的解决方案
# -*- 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)+"
")
p.stdin.close()
p.wait()
print"excution result:
"
pout=''.join(p.stdout.readlines())
output=pout.decode('cp936').encode('utf-8')
print"%s
"% output
begin=begin+1
原文地址:https://www.cnblogs.com/bsmagic/p/4392928.html