首页 > 编程语言 > 详细

python 杂七杂八 :

时间:2016-11-08 13:41:41      阅读:196      评论:0      收藏:0      [点我收藏+]

 

subprocess.Popen(...)

python3 实现代码: 备注write 要使用bytes 在最后结果转为str 显示时才不会出现 b‘‘ 这样的字节显示

import subprocess

obj = subprocess.Popen(["python3"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
obj.stdin.write(bytes(‘print(1)‘,encoding=‘utf-8‘))
# obj.stdin.write(‘print 2 \n ‘)
# obj.stdin.write(‘print 3 \n ‘)
# obj.stdin.write(‘print 4 \n ‘)
obj.stdin.close()

cmd_out = obj.stdout.read()
obj.stdout.close()
cmd_error = obj.stderr.read()
obj.stderr.close()

print(str(cmd_out,encoding=‘utf-8‘))
print(cmd_error)


技术分享

 








python 杂七杂八 :

原文:http://www.cnblogs.com/yaabb163/p/6042477.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!