Sending complex shell command to python subprocess

I am writing a script that uses a number of complex Imagemagick commands in python. I am wondering what to call something like this ...

convert 1.png \( +clone -background black -shadow 110x1+9+9 \) +swap -background none -layers merge +repage 2.png

It’s quite convenient for me to call simple commands with a subprocess, but I don’t yet know how to specify the order of execution (slanted brackets).

Of course, I could use the os.system or the command module, but since they leave the language, I would definitely prefer to use a subprocess.

+3
source share
1 answer

Yes, you want to use subprocess. You just need to put each argument in a separate element in the list of arguments that you pass Popen:

subprocess.Popen(['convert', '1.png', '(', '+clone', '-background', 'black', '-shadow', '110x1+9+9',
                  ')', '+swap', '-background', 'none', '-layers', 'merge', '+repage', '2.png'],
                 otherargments=values, etc=etc)

, .

- ( , , , "(" ")" ), .

+2

All Articles