0

I am trying to execute the following via a python script. But I am getting an error. Unknown option:-a test -b 25 -c 18 --d 25 23

script_args = '-a test -b 25 -c 18 --d 25 23'
subprocess.Popen(['/home/pi/bash/bash_script.sh', script_args])

I can copy the unknown option line and execute my script and the script runs without any errors and I am getting desired output.

 /home/pi/bash/bash_script.sh -a test -b 25 -c 18 --d 25 23

What am I doing incorrectly via the python script?

asked Jul 23, 2018 at 16:15

1 Answer 1

3

You're passing a single argument composed of all those characters.

script_args = ['-a', 'test', ..., '23']
subprocess.Popen(['/home/pi/bash/bash_script.sh'] + script_args)
answered Jul 23, 2018 at 16:18
Sign up to request clarification or add additional context in comments.

1 Comment

You can also unpack arguments into a list using the * operator which, unlike +, supports all iterable types. subprocess.run(['/home/pi/bash/bash_script.sh', *script_args])

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.