Running shell programs from Python
btang at pacific.jpl.nasa.gov
Tue Apr 18 17:33:59 CEST 2000
seh at ffi.no 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?
> Svein-Erik Hamran
Use os.popen() or popen2.popen2().
Here is an example (for Unix):
str1 = os.popen('ls','r').read()
out1,in1 = popen2.popen2('cat')
str2 = out1.read()
More information about the Python-list