Can a python script execute a function inside a bash script? -
i have bash script provided 3rd party defines set of functions. here's template of looks like
$ cat test.sh #!/bin/bash define go() { echo "hello" }
i can following bash shell call go():
$ source test.sh $ go hello
is there way access same function python script? tried following, 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" 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 >>>
yes, indirectly. given foo.sh:
function go() { echo "hi" }
try this:
>>> subprocess.popen(['bash', '-c', '. foo.sh; go'])
output:
hi
Comments
Post a Comment