gpt4 book ai didi

Python - 对已关闭文件的子进程 I/O 操作

转载 作者:行者123 更新时间:2023-12-01 05:02:34 24 4
gpt4 key购买 nike

我尝试过下面的类,使用python2.6中的subporcess模块​​按顺序执行命令。

from subprocess import Popen, PIPE

class BaculaActions():

def __init__(self):
self.console = Popen(["bconsole"], stdout=PIPE, stderr=PIPE, stdin=PIPE)

def run_job(self, jobname, level):
run = self.console.communicate("run job=%s level=%s yes" % (jobname, level))
return(run)

def del_jobid(self, jobid):
delete = self.console.communicate("delete jobid=%s" % (jobid))
return(delete)

但是,如果我尝试以下代码,则会收到错误:ValueError:对已关闭文件进行 I/O 操作

from pconsole import BaculaActions

myconsole = BaculaActions()

run = myconsole.run_job("xxxxx-data", "incremental")
delete = myconsole.del_jobid(25487)

有人知道可能出了什么问题吗?谢谢

最佳答案

手册确实说明了一切:

Popen.communicate(input=None, timeout=None)
Interact with process: Send data to stdin. Read data from stdout and stderr,
until end-of-file is reached. Wait for process to terminate.

运行第一个命令并获得结果后,“bconsole”进程已终止,管道已关闭,因此第二个communicate 调用时出现错误。

关于Python - 对已关闭文件的子进程 I/O 操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25754045/

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