python - 如何在后台使用依赖的 shell 命令运行 python 脚本
问题描述
是否可以在 python 脚本的后台运行 shell 命令?假设我有 run.py 并且在这个脚本中我需要做,
#run shell command(in python script until script is finished)
#continue with script
但问题是它们是依赖的。要运行我的脚本,我需要在同一个脚本中运行 shell 命令。
解决方案
是的,您可以subprocess
在 Python 中使用该库并检查输出的状态。
前任:subprocess.check_call("exit 1", shell=True)
推荐阅读
- python - 在 AWS 上将用户输入值动态注入 Python 代码?
- c - 如何将字符串和数字组合成一个 scanf 函数
- jquery - 如何检查所有作为html元素id的数组元素是否具有值
- python - 如何使陈述成为(或)?
- javascript - 正确转换浮点数?
- php - WordPress 自定义帖子中的多个查询
- java - RxJava:从单个 Observable 传递嵌套数据
- javascript - 使用 Material UI/React Stepper 创建步骤的“页面”(如表格分页)
- reactjs - 对象可能是“未定义”.ts(2532)
- php - PHP中的递归函数用于查找任意节点之间的路径