Python create a Popen shell command list

2020-05-10 02:00发布

问题:

Please can someone help me create a Popen command line list from this...

identify  -format %b:%w:%h:%r:%# myimage.jpg

I have this:

cmd=Popen(['identify -format', '%b:%w:%h:%r:%#', 'myimage.jpg'])

But that does not work. the original command line works fine in the command line. But just cannot get it working in python this way.

回答1:

try this:

cmd=Popen(['identify', '-format', '%b:%w:%h:%r:%#', 'myimage.jpg'])

you have to break down args as a list of separate arguments