Running shell programs from Python

Benyang Tang btang at
Tue Apr 18 17:33:59 CEST 2000

seh at wrote:
> I have just started with Python and have some questions.. I have some
> compiled c programs that I normally run from the shell. I can use | to
> pipe the output from one as input to the next. I would like to call the
> programs from Python. Could someone please indicate how this is done?
> Any references?
> Regards
> Svein-Erik Hamran

Use os.popen() or popen2.popen2(). 


Here is an example (for Unix):

import os,popen2
str1 = os.popen('ls','r').read()
print str1
out1,in1 = popen2.popen2('cat')
str2 =
print str2

Benyang Tang

More information about the Python-list mailing list