标签:src odi log 字节 pen com pytho pre pop
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)
标签:src odi log 字节 pen com pytho pre pop
原文地址:http://www.cnblogs.com/yaabb163/p/6042477.html