The commands Module

The easy way to capture the output of a subprocess

     import commands
     data = commands.getoutput("ls -l")
  • Also includes a quoting function
     arg = mkarg(str)  # Turns str into a argument suitable
                       # for use in the shell (to prevent mischief)

Comments

  • Really this is just a wrapper over the popen2 module.
  • Only available on Unix (sorry).
<<< O'Reilly OSCON 2000, Advanced Python Programming, Slide 55
July 17, 2000, beazley@cs.uchicago.edu
>>>