Seite 1 von 1

subprocess call must contain quotations

Verfasst: Freitag 8. Juli 2016, 13:47
von mleopold
Hi,

I need to call a subprocess with quotations (imagemagick, I now there is PythonMagick but I want to use subprocess)

Call on command line is:

convert logo: -fill white -draw "rectangle 50,50 400,400" abc.png

which works perfectly. Remark: The quotations have to be set.

Calling this on python could look like:

Code: Alles auswählen

import subprocess
params = ['convert', 'logo:', '-fill', '-draw', '"rectangle 50,50 400,400"', 'abc.png']
subprocess.check_call(params)
which does not word. Reson: rectangle prameter is in bad condition.

I tried several combinations like:

Code: Alles auswählen

params = ['convert', 'logo:', '-fill', '-draw', '"rectangle', '50,50', '400,400"', 'abc.png']
params = ['convert', 'logo:', '-fill', '-draw', '\"rectangle', '50,50', '400,400\"', 'abc.png']
etc.

How can I get the quotations into calling the subprocess?

Re: subprocess call must contain quotations

Verfasst: Freitag 8. Juli 2016, 13:52
von snafu
Just leave out the quotations:

Code: Alles auswählen

params = ['convert', 'logo:', '-fill', '-draw', 'rectangle 50,50 400,400', 'abc.png']
subprocess.check_call(params)
Quotations are meant to tell your shell that something should be interpreted as a single argument. In contrast, the subprocess API takes them as a part of the argument. This is why your code fails.

Re: subprocess call must contain quotations

Verfasst: Freitag 8. Juli 2016, 13:55
von mleopold
Facepalm :? . Thanks! :D

Re: subprocess call must contain quotations

Verfasst: Freitag 8. Juli 2016, 14:00
von snafu
BTW: Why did your account switch from speaking German to English?
(search.php?author_id=14028&sr=posts)

Re: subprocess call must contain quotations

Verfasst: Freitag 8. Juli 2016, 14:12
von mleopold
:oops: Das war die Macht der Gewohnheit. Zweite Facepalm. :wink:

Re: subprocess call must contain quotations

Verfasst: Freitag 8. Juli 2016, 14:20
von snafu
Heute nicht dein Tag, was? ;)