I’m writing a script that uses a series of complex Imagemagick commands in python.
I’m wondering how to call something like this…
convert 1.png \( +clone -background black -shadow 110x1+9+9 \) +swap -background none -layers merge +repage 2.png
I am perfectly comfortable calling simple commands with subprocess, but I do not yet know how to specify the order of execution (the escaped parentheses).
Surely I could use os.system or the commands module, but since these are leaving the language, I would definitely prefer to use subprocess.
Yes, you want to use
subprocess. You simply need to put each argument in a separate item in the list of arguments you give toPopen:You can also build up that argument list beforehand, in case your order of arguments needs to change.
You don’t need to do any escaping of arguments (for things like spaces inside an argument, or other special shell characters like “(” and “)”), since this isn’t going to be interpreted by a shell.