Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

subprocess.call requiring all parameters to be separated by commas

Tags:

I used to be able to do a subprocess.call(["command","-option value -option value"]) and it would work there was a change to the command to work properly with things in quotes, but now I have to change my subprocess call command to look like this:

subprocess.call(["command","-option","value","-option","value"])

is there something I can do to get it to work the other way again in python?

the os.system("command -option value -option value") works the same as it did before.

like image 524
Dag Avatar asked Nov 03 '10 20:11

Dag


1 Answers

Avoid shell=True if you can -- it's a security risk. For this purpose, shlex.split suffices:

import subprocess
import shlex
subprocess.call(shlex.split("command -option value -option value"))
like image 51
unutbu Avatar answered Nov 08 '22 23:11

unutbu