如何向子进程发送新命令 [英] How to send a new command to a subprocess
问题描述
我之前问过一个问题 关于如何设置 tkinter gui 以在不挂起整个程序的情况下从子进程接收行.现在可以正常使用了.
I previously asked a question about how to set up a tkinter gui to recieve lines from a subprocess without the entire program hanging. That is now functional.
现在,我不知道如何将新行发送到子进程.我曾尝试使用 process.communicate,但我可能一直在错误地使用它.我也试过 这个问题的解决方案,但 self.process.stdin.write('stop\n'.encode())
似乎不起作用.如何向子 python 子进程发送新命令?
Now, I can't figure out how to send new lines to a subprocess. I've tried using process.communicate, but I might have been using it wrong. I also tried this question's solution, but self.process.stdin.write('stop\n'.encode())
doesn't seem to work. How do I send new commands to the child python subprocess?
相关代码:
self.process = subprocess.Popen([ "python", "-u", dir + "start.py" ],
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
stderr=subprocess.PIPE,
cwd=dir)
推荐答案
数据可能卡在管道中.写入后添加self.process.stdin.flush()
.
The data may be stuck in the pipe. Add self.process.stdin.flush()
after the write.
这篇关于如何向子进程发送新命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!