source: trunk/essentials/dev-lang/python/Lib/commands.py@ 3226

Last change on this file since 3226 was 3225, checked in by bird, 19 years ago

Python 2.5

File size: 2.2 KB
Line 
1"""Execute shell commands via os.popen() and return status, output.
2
3Interface summary:
4
5 import commands
6
7 outtext = commands.getoutput(cmd)
8 (exitstatus, outtext) = commands.getstatusoutput(cmd)
9 outtext = commands.getstatus(file) # returns output of "ls -ld file"
10
11A trailing newline is removed from the output string.
12
13Encapsulates the basic operation:
14
15 pipe = os.popen('{ ' + cmd + '; } 2>&1', 'r')
16 text = pipe.read()
17 sts = pipe.close()
18
19 [Note: it would be nice to add functions to interpret the exit status.]
20"""
21
22__all__ = ["getstatusoutput","getoutput","getstatus"]
23
24# Module 'commands'
25#
26# Various tools for executing commands and looking at their output and status.
27#
28# NB This only works (and is only relevant) for UNIX.
29
30
31# Get 'ls -l' status for an object into a string
32#
33def getstatus(file):