gpt4 book ai didi

python - 使用 subprocess.Popen 顺序执行 python 脚本

转载 作者:行者123 更新时间:2023-11-30 17:29:57 27 4
gpt4 key购买 nike

我正在使用 python 的 subprocess 针对 C 代码库执行脚本。具体来说,我有许多脚本,针对程序的单个实例逐一运行。这是我想做的:

start process ABC

execute python scripts 01 against ABC and store output from ABC in file A

execute python scripts 02 against ABC and store output from ABC in file B

execute python scripts 03 against ABC and store output from ABC in file C

我目前的计划

myProcess = subprocess.Popen(PATH, BUFFSIZE, STDOUT= myFilePointer ...)

但这无法从进程 ABC 的每次执行中产生返回输出,并且仅记录脚本 01 的输出,而不记录其余的输出。

我看过official documentation及其他resources但找不到。

最佳答案

试试这个:

 cmd = subprocess.Popen("ABC %s" % command,
stdout=out,
stderr=subprocess.PIPE)
stdout, stderr = cmd.communicate()
retcode = cmd.returncode

使用命令参数将命令行参数传递给ABC。执行 Popen 后,ABC 的输出将存储在 stdout 中。可能发生的错误将存储到stderr

关于python - 使用 subprocess.Popen 顺序执行 python 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25420220/

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