I have a bash script in which I have a function like this
configure()
{
echo $1
echo $2
return 0
}
And I am calling this function directly like this from my python file
subprocess.Popen(
['bash', ' -c', '. test.sh; configure 1 2'])
now I want to get return value from this function and in case there is some error I want to catch that as well.
configure 1 2to your script at all. You're passing that string to bash, but not telling bash to pass it on to your script.['bash', ' -c', '. test.sh; configure 1 2']-- both commands need to be included in the argument immediately after-cto be considered part of the script bash is supposed to run. The next argument after that goes into$0, the one after that into$1, etc -- but the script you're telling bash to run ignores$0,$1, etc. entirely.echo "$1"with the quotes; see I just assigned a variable, butecho $variableshows something else.bash -c, you might as well just pass the whole string tosubprocess.Popen()and use theshell=Trueoption.