os.popen is really great when you need to drive a text based software. Here is a sample of use which create animated graphics using the free software gnuplot.
1 2 3 4 5 6
import os f=os.popen('gnuplot', 'w') print >>f, "set yrange[-300:+300]" for n in range(300): print >>f, "plot %i*cos(x)+%i*log(x+10)" % (n,150-n) f.flush()
c.l.py don't mention very often the os.popen function. But it can be a very great tool when you want to use python as a glue language.
In this sample: The f=os.popen('gnuplot', 'w') create a file like object which is connected to the input (stdin) of the software launched (note that os.popen('gnuplot') would have open a file linked to the output (stdout)). After you only have to write into this file the same things that you would have written if you had used your software interactively.
The popen2 module give alternate functions that allow to access in the same time both to stdin, stdout and stderr (sample on http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/117221)