Execute a BASH command in Python-- in the same process
Posted
by Baldur
on Stack Overflow
See other posts from Stack Overflow
or by Baldur
Published on 2010-05-18T15:57:43Z
Indexed on
2010/05/18
16:21 UTC
Read the original article
Hit count: 305
I need to execute the command . /home/db2v95/sqllib/db2profile
before I can import ibm_db_dbi
in Python 2.6.
Executing it before I enter Python works:
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
>>>
but executing it in Python using os.system(". /home/db2v95/sqllib/db2profile")
or subprocess.Popen([". /home/db2v95/sqllib/db2profile"])
results in an error. What am I doing wrong?
Edit: this is the error I receive:
> 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
© Stack Overflow or respective owner