The commands Module

(Unix only) The commands module contains a few convenience functions designed to make it easier to execute external commands under Unix. Example 3-7 demonstrates this module.

Example 3-7. Using the commands Module

File: commands-example-1.py

import commands

stat, output = commands.getstatusoutput("ls -lR")

print "status", "=>", stat
print "output", "=>", len(output), "bytes"

status => 0
output => 171046 bytes

Get Python Standard Library now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.