Chris Hellyar wrote:

>Hi-ho,
>
>A newbie python question..
>
>What's the command to execute a program under python..
>
>ie: I want to use imagemagic to modify an image, I've got the command line
>in a string, and want to pass it to bash..
>
>I'm just modifying some scripts written by a contractor a few months ago,
>and haven't done much work in python, and the online help wasn't so thought
>I'd see if we have any experts in the clug :-).
>
>Cheers,  Chris Hellyar.
>

If all you want to do is execute the program, and not capture the 
output, then the os.system() command is what you need, eg:

 >>> import os
 >>> args = '-lG /usr/X11R6/'
 >>> os.system('ls %s' % (args, ))
total 11
drwxr-xr-x    2 root         3616 Mar 22 19:32 bin
drwxr-xr-x    2 root           48 Feb  7  1996 doc
drwxr-xr-x    5 root          184 Mar  9 13:35 include
drwxr-xr-x    5 root          120 Mar 11 15:54 LessTif
drwxr-xr-x    5 root         3712 Apr  4 17:25 lib
drwxr-xr-x    7 root          192 Mar  9 13:02 man
drwxr-xr-x    3 root           72 Mar 10 00:19 share
0
 >>>

If however you need to capture the programs output, you will need to 
have a look at the popen2 module, which I am not to familiar with so 
cannot provide an example.

Mark

Reply via email to