gpt4 book ai didi

python - 如何向子进程发送新命令

转载 作者:行者123 更新时间:2023-11-28 16:35:07 25 4
gpt4 key购买 nike

我之前问过一个 question关于如何设置一个 tkinter gui 以在整个程序不挂起的情况下从子进程接收行。现在可以使用了。

现在,我不知道如何向子进程发送新行。我试过使用 process.communicate,但我可能用错了。我也试过this question's solution ,但 self.process.stdin.write('stop\n'.encode()) 似乎不起作用。如何向子 python 子进程发送新命令?

相关代码:

self.process = subprocess.Popen([ "python", "-u", dir + "start.py" ], 
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
stderr=subprocess.PIPE,
cwd=dir)

最佳答案

数据可能卡在管道中。在写入后添加self.process.stdin.flush()

关于python - 如何向子进程发送新命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27334037/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com