[Tutor] executing a external program

Gerrit Holl gerrit@nl.linux.org
Wed, 2 Feb 2000 15:48:01 +0100


Hello,

On Wed, Feb 02, 2000 at 08:18:15AM -0600, Mike Partin wrote:
> Does anyone have any examples of this..... especially executing a program that
> uses switches for example cvs.

You can use different functions for that.
If you don't need to capture the output but print is as is (like you
do when you run a program amnually from the shell), use os.system:
Like:
os.system("cvs commit -m 'My script changed something' file.c")

If you do need to capture the output, you can use os.popen, like:

fp = os.popen("cvs commit -m 'My script changed something' file.c")
output = fp.read()

If you need to capture errors also (likely if you need it for CVS), have
a look at the popen2 module.

regards,
Gerrit.

-- 
-----BEGIN GEEK CODE BLOCK----- http://www.geekcode.com
Version: 3.12
GCS dpu s-:-- a14 C++++>$ UL++ P--- L+++ E--- W++ N o? K? w--- !O !M !V PS+ PE?
Y? PGP-- t- 5? X? R- tv- b+(++) DI D+ G++ !e !r !y
-----END GEEK CODE BLOCK-----