[Tutor] subprocess.call

Sander Sweers sander.sweers at gmail.com
Mon Jul 27 21:25:16 CEST 2009

On Mon, 2009-07-27 at 14:40 -0400, davidwilson at Safe-mail.net wrote:
> OK I think I found my error, here is what I did:
> flags = set([file for file in glob.glob('flag-*.svg')])
> def call(cmd):
>     subprocess.call([cmd], shell=True)

You hardly ever need shell=True. And using [cmd] is close but still not
the way. Change it to simply cmd and read on.

I would create an intermediate step creating the command you want
suprocess to run. The first 3 parts never change in your script below.

c = ['svg2png', '--width=17', '--height=12']

> for flag in flags:
>     name = flag[:-4]
>     out = name+'.png'

You can add a list to a list so I would write the below as.

      call(c + [flag, out])

>     call('svg2png --width=17 --height=12 %s %s' \
>                % (flag, out))

This should make subprocess take your full command. Whether the command
is correct is another question ;-)


More information about the Tutor mailing list