37,719
社区成员
发帖
与我相关
我的任务
分享
import os
import sys
opt1 = raw_input('this is opt1 raw input:')
print 'opt1 is:',opt1
opt2 = raw_input('this is opt2 raw input:')
print 'opt2 is:',opt2
opt3 = raw_input('this is opt3 raw input:')
print 'opt3 is:',opt3
opt4 = raw_input('this is opt4 raw input:')
print 'opt4 is:',opt4
p = subprocess.Popen("python subpro.py", stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) #1111
while True:
line = p.stdout.readline()
print line
if not line:
break
if line.startswith('this is opt1'):
opt = 'aaa'
elif line.startswith('this is opt2'):
opt = 'bbb'
elif line.startswith('this is opt3'):
opt = 'ccc'
elif line.startswith('this is opt4'):
opt = 'ddd'
p.stdin.write(opt+os.linesep)
raw_input('this is opt1 raw input:\n')
your code here...
print '>>{x}[%s]' % line
#!/usr/bin/python
import sys
sys.stdout.write('this is opt1 raw input:\n')
sys.stdout.flush()
opt1=sys.stdin.readline()
print 'opt1 is:',opt1
sys.stdout.write('this is opt2 raw input:\n')
sys.stdout.flush()
opt2=sys.stdin.readline()
print 'opt2 is:',opt2
#!/usr/bin/python
import os
import sys
import subprocess
# call mib2c
def callmib():
exestr = 'python -u subpro.py'
p = subprocess.Popen(exestr, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
while True:
line = p.stdout.readline()
print line
if not line:
break
if line.startswith('this is opt1'):
opt = 'aaa'
elif line.startswith('this is opt2'):
opt = 'bbb'
p.stdin.write(opt+os.linesep)
p.wait()
errout = p.stderr.read()
p.stdout.close()
p.stderr.close()
p.stdin.close()
print
# main funciton
# Step 1. make C files first time
callmib()
raw_input('...')
sys.stdout.write('...')
sys.stdout.flush()
sys.stdin.readline()
raw_input('this is opt1 raw input:\n')