![](/img/trans.png)
[英]python multiprocessing - sending child process logging to GUI running in parent
[英]python sending argument to a running process
I have a flutter project called zed
, my goal is to monitor the output of flutter run
, as long as pressing r
, the output will increase.
为了自动实现这个工作流程,我的实现是
import subprocess
bash_commands = f'''
cd ../zed
flutter run --device-id web-server --web-hostname 192.168.191.6 --web-port 8352
'''
process = subprocess.Popen('/bin/bash', stdin=subprocess.PIPE, stdout=subprocess.PIPE, shell=False)
output, err= process.communicate(bash_commands.encode('utf-8'))
print(output, err)
output, _ = process.communicate('r'.encode('utf-8'))
print(output)
它没有像我预期的那样工作,屏幕上没有打印任何内容。
process.stdin.write(bash_commands)
process.stdin.flush()
Popen.communicate(input=None, timeout=None)
与进程交互:向标准输入发送数据。 从 stdout 和 stderr 读取数据,直到到达文件结尾
在 pipe 关闭之前, communicate(...)
不会返回,这通常发生在子进程关闭时。 非常适合ls -l
对于长时间运行的子进程不太好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.