【发布时间】:2022-01-12 13:28:20
【问题描述】:
我有以下路径:
airflow_home = os.path.join("opt", "airflow")
airflow_docs = os.path.join(airflow_home, "docs")
我希望在 bash 命令中使用 airflow_docs 路径。为此,我使用了以下代码:
subprocess.run([f"sphinx-apidoc -o ./ ../plugins"],
shell=True,
cwd=airflow_docs)
我收到一个错误FileNotFoundError。
但是,这确实有效:
subprocess.run([f"sphinx-apidoc -o ./ ../{doc_module}"],
shell=True,
cwd="/opt/airflow/docs")
因此,似乎缺少前导斜杠会导致问题。我在谷歌搜索了关于在路径中添加前导斜杠但没有成功。那么,subprocess.run 是否可以使用 os.path 包,还是必须使用硬编码字符串?
【问题讨论】:
标签: python subprocess