【发布时间】:2011-04-15 07:36:35
【问题描述】:
我在这个目录下有一个 python 脚本:
work/project/test/a.py
在a.py 内部,我使用subprocess.POPEN 从另一个目录启动进程,
work/to_launch/file1.pl, file2.py, file3.py, ...
Python 代码:
subprocess.POPEN("usr/bin/perl ../to_launch/file1.pl")
在工作/项目/下,我输入以下内容
[user@machine project]python test/a.py,
error "file2.py, '没有这样的文件或目录'"
如何添加work/to_launch/,以便找到这些依赖文件file2.py?
【问题讨论】:
-
你可以尝试在 Popen 中使用 cwd 参数:stackoverflow.com/questions/1685157/…
-
在 Python 中使用
import os然后os.chdir('/tmp/yourdirectory')这将为您的 python 脚本设置当前目录。
标签: python subprocess working-directory