using Python to run other programs

Sagiv Malihi malihi1 at 012.net.il
Tue Nov 18 15:55:09 EST 2003


hi,
using python to run shell commands is very easy.
all you need to do is create the command line you would want to run. in your
case:
command = "pgp -feat " + a
and then run it using os.system(), like this:
import os
os.system(command)


if you also want to get the output of the command, you can use the
'commands' module, like this:
import commands

output, rc = commands.getoutput(command)

then you get the output into the variable 'output', and the exit code of the
program into the variable 'rc'.

        sagiv.


"Frog" <FrogRemailer at bigfoot.com> wrote in message
news:7T02VNBM37943.8988541667 at Gilgamesh-frog.org...
> Hi, i'm not a programmer so I have a very stupid question.  I'm trying to
> make a practical script.  I need to run an executable program in it but i
> can't get it to work.  Maybe someone here can figure it out easily:
>
> -----
> #! /python
>
> a = (recipient's e-mail address)
>
> pgp -feat a
>
> (sendmail to address after encryption)
> ------
>
> How do I get python to open the pgp program?
>
> Should I use an environment other than python?
>
> thanks!
>
>






More information about the Python-list mailing list