I have a bash script provided by a 3d party which defines a set of functions. Here's a template of what that looks like
$ cat test.sh
#!/bin/bash
define go() {
echo "hello"
}
I can do the following from a bash shell to call go():
$ source test.sh
$ go
hello
Is there any way to access the same function from a python script? I tried the following, but it didn't work:
Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> subprocess.call("source test.sh")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.6/subprocess.py", line 470, in call
return Popen(*popenargs, **kwargs).wait()
File "/usr/lib/python2.6/subprocess.py", line 623, in __init__
errread, errwrite)
File "/usr/lib/python2.6/subprocess.py", line 1141, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
>>>
bash
that you can't duplicate inPython
? – ghostdog74 Apr 29 '11 at 0:18