Communicate with running process via STDOUT
i have created a running process which listens for input:
listen = Popen(["home/user/listen"], stdout=PIPE,开发者_如何学运维 stdin=PIPE)
It runs and awaits input from STDIN/STDOUT.
Unfortunately, it seems that I can't execute anything I send to the process, i.e. like you would by pressing "Enter", e.g.
listen.communicate("Test")
or
listen.stdout("Test")
Writes the string to STDOUT but doesn't execute it, I have to press "Enter" manually. Any way to fix this?
P.S. I'm refering to http://docs.python.org/library/subprocess.html
Does home/user/listen
wait for the line end? If so, add \n
at the end of your commands, like listen.communicate("Test\n")
.
I found a solution:
listen.stdin.write("%s" %input)
listen.stdin.write("\n")
精彩评论