先运行命令1,数据处理大约需要半分钟的时间,
之后依次输入要处理的数据2并获取输出3.
2和3这两个多次重复。
试过os.system Popen 还有subprocess好像都不能在1之后再输入2,无法交互式处理命令行,也就无法获取到3

1 mengjue Jan 7, 2015 try pexpect module |
2 clino Jan 7, 2015 subprocess 可以啊,往 stdin 里面写不就行了吗? |
3 Delbert OP @clino @mengjue ```python concept_file = open('concepts.txt', 'rt') p = Popen('./distance vectors.bin', stdin=PIPE,stdout=PIPE, bufsize=1) time.sleep(30) word = concept_file.readline() print(word) Popen.stdin = word Popen.stdin = 'EXIT' print(p.stdout.readlines()) concept_file.close() ``` 之后就卡住了,一动不动,换成read()和readline()也都一样。。。。 |
4 clino Jan 7, 2015 问题出在 readlines https://docs.python.org/2/library/stdtypes.html#file.readlines 这个借口是一直阻塞直到读完的 你用楼上提到的 pexpect 吧,这个是专门做这种用途的吧 |
5 brickgao Jan 7, 2015 |