Executing a command from within python using the subprocess module

Aahz aahz at pythoncraft.com
Thu Feb 18 22:40:42 CET 2010


In article <5YudnaFysO8HouTWnZ2dnUVZ_tidnZ2d at westnet.com.au>,
R (Chandra) Chandrasekhar <chyavana at gmail.com> wrote:
>
>---
>import subprocess
>
>width = 5
>height = 30
>colors = ['#abcdef]', '#456789']
>filename = "/tmp/image.png"
>
># I want to get the equivalent of variable interpolation in Perl
># so that the command
>#
># convert -size 5x30 gradient:#abcdef-#456789 /tmp/image.png

Here's the equivalent of Peter's cute code in simpler form:

cmd = [
    'convert',
    '-size',
    '%sx%s' % (width, height),
    'gradient:%s-%s' % tuple(colors),
    # above could also be: 'gradient:%s-%s' % (colors[0], colors[1]),
    filename,
    ]
subprocess.Popen(cmd)
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"At Resolver we've found it useful to short-circuit any doubt and just        
refer to comments in code as 'lies'. :-)"



More information about the Python-list mailing list