【发布时间】:2014-02-19 19:52:12
【问题描述】:
我想在子目录/超级目录中执行一个脚本(我需要首先在这个子目录/超级目录中)。我无法让subprocess 进入我的子目录:
tducin@localhost:~/Projekty/tests/ve$ python
Python 2.7.4 (default, Sep 26 2013, 03:20:26)
[GCC 4.7.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> import os
>>> os.getcwd()
'/home/tducin/Projekty/tests/ve'
>>> subprocess.call(['cd ..'])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/subprocess.py", line 524, in call
return Popen(*popenargs, **kwargs).wait()
File "/usr/lib/python2.7/subprocess.py", line 711, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1308, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
Python 抛出 OSError,我不知道为什么。无论我是尝试进入现有的子目录还是向上一个目录(如上所述)都没有关系 - 我总是会遇到同样的错误。
【问题讨论】:
-
如果改用
os.chdir()会发生什么。
标签: python subprocess