繁体   English   中英

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

[英]Executing python scripts sequentially using subprocess.Popen

我正在使用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的情况下记录输出,而在其余情况下不记录输出。

我查看了官方文档和其他资源,但找不到。

尝试这个:

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM