1
mengjue 2015-01-07 15:42:52 +08:00
try pexpect module
|
2
clino 2015-01-07 15:43:15 +08:00
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 2015-01-07 16:26:29 +08:00
问题出在 readlines
https://docs.python.org/2/library/stdtypes.html#file.readlines 这个借口是一直阻塞直到读完的 你用楼上提到的 pexpect 吧,这个是专门做这种用途的吧 |
5
brickgao 2015-01-07 23:51:11 +08:00
|