首页 > 解决方案 > 如何在后台使用依赖的 shell 命令运行 python 脚本

问题描述

是否可以在 python 脚本的后台运行 shell 命令?假设我有 run.py 并且在这个脚本中我需要做,

#run shell command(in python script until script is finished)
#continue with  script

但问题是它们是依赖的。要运行我的脚本,我需要在同一个脚本中运行 shell 命令。

标签: pythonshell

解决方案


是的,您可以subprocess在 Python 中使用该库并检查输出的状态。

前任:subprocess.check_call("exit 1", shell=True)


推荐阅读