subprocess call must contain quotations

Wenn du dir nicht sicher bist, in welchem der anderen Foren du die Frage stellen sollst, dann bist du hier im Forum für allgemeine Fragen sicher richtig.
Antworten
mleopold
User
Beiträge: 15
Registriert: Dienstag 4. Juni 2013, 16:05

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?
Benutzeravatar
snafu
User
Beiträge: 6740
Registriert: Donnerstag 21. Februar 2008, 17:31
Wohnort: Gelsenkirchen

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.
Zuletzt geändert von snafu am Freitag 8. Juli 2016, 13:56, insgesamt 1-mal geändert.
mleopold
User
Beiträge: 15
Registriert: Dienstag 4. Juni 2013, 16:05

Facepalm :? . Thanks! :D
Benutzeravatar
snafu
User
Beiträge: 6740
Registriert: Donnerstag 21. Februar 2008, 17:31
Wohnort: Gelsenkirchen

BTW: Why did your account switch from speaking German to English?
(search.php?author_id=14028&sr=posts)
mleopold
User
Beiträge: 15
Registriert: Dienstag 4. Juni 2013, 16:05

:oops: Das war die Macht der Gewohnheit. Zweite Facepalm. :wink:
Benutzeravatar
snafu
User
Beiträge: 6740
Registriert: Donnerstag 21. Februar 2008, 17:31
Wohnort: Gelsenkirchen

Heute nicht dein Tag, was? ;)
Antworten