0

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.

20
  • You aren't passing configure 1 2 to your script at all. You're passing that string to bash, but not telling bash to pass it on to your script. Commented Nov 16, 2020 at 21:08
  • Compare it to ['bash', ' -c', '. test.sh; configure 1 2'] -- both commands need to be included in the argument immediately after -c to 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. Commented Nov 16, 2020 at 21:08
  • You should figure out how to run your bash script to get the output you want first, and only get Python involved after Commented Nov 16, 2020 at 21:09
  • BTW, it should be echo "$1" with the quotes; see I just assigned a variable, but echo $variable shows something else. Commented Nov 16, 2020 at 21:10
  • If you're going to call bash -c, you might as well just pass the whole string to subprocess.Popen() and use the shell=True option. Commented Nov 16, 2020 at 21:11

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.