views:

192

answers:

2

Command:

root@host:~#convert source.jpg -resize x500 -resize "500x<" -gravity center +repage target.jpg

Python code:

>> command_list = ['convert', 'source.jpg', '-resize', 'x500', '-resize', '\'500x<\'', '-gravity', 'center', 'target.jpg']
>> p = subprocess.call(command_list)
convert: invalid argument for option `'500x<'': -resize.

What's wrong in above code?

+4  A: 

Why the extra quotes on 500x<? Subprocess will correctly quote any arguments.

Keep in mind that the shell will NOT pass the outer quotes to the application, just the quoted value, but subprocess will pass the quotes if you force it to.

gahooa
More precisely, arguments don't need quoting in general -- only when you're passing a command line to the shell or system()
jleedev
A: 

Have you tried '"500x<"' instead of '\'500x<\''?

Davide