【发布时间】:2010-05-18 15:57:43
【问题描述】:
我需要先执行命令. /home/db2v95/sqllib/db2profile,然后才能在 Python 2.6 中执行import ibm_db_dbi。
在我进入 Python 之前执行它是可行的:
baldurb@gigur:~$ . /home/db2v95/sqllib/db2profile
baldurb@gigur:~$ python
Python 2.6.4 (r264:75706, Dec 7 2009, 18:45:15)
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ibm_db_dbi
>>>
但是在 Python 中使用 os.system(". /home/db2v95/sqllib/db2profile") 或 subprocess.Popen([". /home/db2v95/sqllib/db2profile"]) 执行它会导致错误。我做错了什么?
编辑:这是我收到的错误:
> Traceback (most recent call last):
> File "<file>.py", line 8, in
> <module>
> subprocess.Popen([". /home/db2v95/sqllib/db2profile"])
> File
> "/usr/lib/python2.6/subprocess.py",
> line 621, in __init__
> errread, errwrite) File "/usr/lib/python2.6/subprocess.py",
> line 1126, in _execute_child
> raise child_exception OSError: [Errno 2] No such file or directory
【问题讨论】:
-
总猜测,但似乎脚本实际上在环境中设置了一些东西,这可能无法通过执行子进程来工作。
-
@abyx: 但这与给定的问题无关,即使它是真的
标签: python bash db2 subprocess