python - subprocess.Popen [Errno 2] 没有这样的文件或目录
问题描述
我编写了一些在 Stream 中使用的脚本。我做了一些,现在我尝试做一个集中我所有脚本的启动器。
我认为我在子流程方面做得很好,但我在 atm 遇到了一些困难。
我尝试使用这一行启动脚本:
subprocess.Popen(['python', "E:/path/rocksmith/rocksmith.pyw"], shell=True)
但是 python 给我一个 No such file or directory 错误。在我想启动的脚本中(rocksmith.pyw),我用 open() 打开了一些文本文件,我猜 python 找不到 .txt 文件,因为 .txt 不在启动器目录中,对吗?
我的目录是这样的:
Launcher folder
- launcher.py
* Script 1 folder
- Script1.py
- text.txt
* Script 2 folder
- Script2.py
- text.txt
* Script 3 folder
- Script3.py
- image.gif
我不知道我的解释是否可以。我只是想在“超级脚本”中启动一些脚本。
谢谢。
解决方案
rocksmith.pyw
如果在尝试打开文件时发生错误,您可能需要使用cwd
kwarg 来Popen
. 这将更改运行脚本的工作目录,因此其中的相对路径rocksmith.pyw
将按照您的预期解析。
subprocess.Popen(['python', "E:/path/rocksmith/rocksmith.pyw"], cwd='/path/to/rocksmith/stuff')
推荐阅读
- docker - Jib maven 插件无法将图像从本地推送到 DockerHub
- python - 有没有办法使用替代构造函数类方法进行子类化?
- spring-webflux - spring webclient 可以与不基于反应的 RESTful API 一起使用吗?
- python - 如何理解python中的字节输出?
- html - 如何仅显示动态生成的特定悬停 div 的工具提示
- javascript - 类型“字符串”不可分配给 react-router-dom 链接组件的类型
- c# - 如何使用 EF 5 linq 方法从多个表中检索数据
- angular - 角垫按钮样式未在垫对话框中应用
- go - 错误:无法加载值。yaml:将 YAML 转换为 JSON 时出错:yaml:行 **:未找到预期的密钥
- javascript - 一个表单上的多个按钮