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
user3525290
1,6192 gold badges29 silver badges48 bronze badges
1 Answer 1
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
Ignacio Vazquez-Abrams
804k160 gold badges1.4k silver badges1.4k bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
Håken Lid
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])default