python - 如何从 python 脚本重新启动 nginx?
问题描述
我可以使用"nginx -s reload"
命令在 shell 上重新启动 nginx。但是,当我使用os.system("nginx -s reload")
命令时,它会出现错误。
/usr/local/bin/nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory
对于这个错误。我已经安装了pcre。是不是有一些魔法问题。
解决方案
要在 python 脚本中运行此类命令,最好使用subprocess library。
试试这个代码而不是你的:
import subprocess
subprocess.call('whatever command you want to run it in terminal', shell=True)
走运
推荐阅读
- android - 后台线程完成工作后如何向前移动主线程
- html - 如何对 HTML 中的图像进行分类并显示所有通过超链接单击给定类别的图像
- java - 将对话框流依赖项添加到我的 android 应用程序后出现重复类错误
- java - 如何将字符串拆分为关于特定分隔符的所有可能的连续组合
- c# - 仅在具有授权属性的端点上有条件地使用中间件
- http - WebLogic 为空主机头请求返回错误请求
- python - Airflow Docker 映像未按预期处理 Python 模块
- google-cloud-platform - 如何防止 GCE 实施者删除 SSH/HTTP/HTTPS 防火墙规则?
- linux - 为什么我无法通过这个 linux shell 脚本检测文件是否存在?
- javascript - 我怎样才能使这个实现更短?