如何附加到 运行 Popen 进程
How to attach to running Popen process
我有一个 shell 脚本,它运行一段时间然后接受输入。
我要创建流程:
process = subprocess.Popen(
'/my/longscript/wait.sh',
shell=True,
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True
)
process
<subprocess.Popen at 0x7fb7b319ef60>
process.pid
10248
然后在不同的会话中附加到此进程并向其发送一些标准输入。我如何使用 pid 重新附加到进程,或者我该怎么做?
running_process = subprocess.attach_to_my_old_process(pid=10248)???
running_process.communicate(input='someinput')
将我的评论变成答案:你必须为此使用命名管道。
我在您的 中回答了如何做到这一点。
我有一个 shell 脚本,它运行一段时间然后接受输入。 我要创建流程:
process = subprocess.Popen(
'/my/longscript/wait.sh',
shell=True,
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True
)
process
<subprocess.Popen at 0x7fb7b319ef60>
process.pid
10248
然后在不同的会话中附加到此进程并向其发送一些标准输入。我如何使用 pid 重新附加到进程,或者我该怎么做?
running_process = subprocess.attach_to_my_old_process(pid=10248)???
running_process.communicate(input='someinput')
将我的评论变成答案:你必须为此使用命名管道。
我在您的