请大家帮忙看看,>_<
运行环境 虚拟机 ubuntu12.04 python3.5.1
用 input() python3 运行失败
用 raw_input(), python2 运行成功
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import time
p = os.pipe()
childpid = os.fork()
if (childpid==0):
os.close(p[1])
while True:
time.sleep(3)
print('reading')
msg = os.read(p[0],1024)
print(msg)
if msg == '':
print('can not read anything')
break
if (msg == 'q'):
os.close(p[0])#关闭管道
break
else:
os.close(p[0])
while True:
#python3.5 中运行出错
str1 = input()
#python2.7 中运行正确
#str1 = raw_input('input anything:')
os.write(p[1],str1)
if(str1 == 'q'):
os.close(p[1])#关闭管道
os.wait()
break
出错信息如图: