I have a bash script provided by a 3rd party which defines a set of functions. Here\'s a template of what that looks like
$ cat test.sh
#!/bin/bash
define
Based on @samplebias solution but with some modification that worked for me,
So I wrapped it into function that loads bash script file, executes bash function and returns output
def run_bash_function(library_path, function_name, params):
params = shlex.split('"source %s; %s %s"' % (library_path, function_name, params))
cmdline = ['bash', '-c'] + params
p = subprocess.Popen(cmdline,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = p.communicate()
if p.returncode != 0:
raise RuntimeError("'%s' failed, error code: '%s', stdout: '%s', stderr: '%s'" % (
' '.join(cmdline), p.returncode, stdout.rstrip(), stderr.rstrip()))
return stdout.strip() # This is the stdout from the shell command