开发者

Communicate with running process via STDOUT

开发者 https://www.devze.com 2023-02-13 23:23 出处:网络
i have created a running process which listens for input: listen = Popen([\"home/user/listen\"], stdout=PIPE,开发者_如何学运维 stdin=PIPE)

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")
0

精彩评论

暂无评论...
验证码 换一张
取 消