rest25/library/commands.rst => rest262/library/commands.rst
6   :platform: Unix
7   :synopsis: Utility functions for running external commands.
8.. sectionauthor:: Sue Williams <sbw@provis.com>
9
10
11The :mod:`commands` module contains wrapper functions for :func:`os.popen` which
12take a system command as a string and return any output generated by the command
13and, optionally, the exit status.
n14+ 
15+The :mod:`subprocess` module provides more powerful facilities for spawning new
16+processes and retrieving their results.  Using the :mod:`subprocess` module is
17+preferable to using the :mod:`commands` module.
18+ 
19+.. warning::
20+ 
21+   In 3.x, :func:`getstatus` and two undocumented functions (:func:`mk2arg` and
22+   :func:`mkarg`) have been removed.  Also, :func:`getstatusoutput` and
23+   :func:`getoutput` have been moved to the :mod:`subprocess` module.
14
15The :mod:`commands` module defines the following functions:
16
17
18.. function:: getstatusoutput(cmd)
19
20   Execute the string *cmd* in a shell with :func:`os.popen` and return a 2-tuple
21   ``(status, output)``.  *cmd* is actually run as ``{ cmd ; } 2>&1``, so that the
31
32
33.. function:: getstatus(file)
34
35   Return the output of ``ls -ld file`` as a string.  This function uses the
36   :func:`getoutput` function, and properly escapes backslashes and dollar signs in
37   the argument.
38
n49+   .. deprecated:: 2.6
50+      This function is nonobvious and useless.  The name is also misleading in the
51+      presence of :func:`getstatusoutput`.
52+ 
53+ 
39Example::
40
41   >>> import commands
42   >>> commands.getstatusoutput('ls /bin/ls')
43   (0, '/bin/ls')
44   >>> commands.getstatusoutput('cat /bin/junk')
45   (256, 'cat: /bin/junk: No such file or directory')
46   >>> commands.getstatusoutput('/bin/junk')
47   (256, 'sh: /bin/junk: not found')
48   >>> commands.getoutput('ls /bin/ls')
49   '/bin/ls'
50   >>> commands.getstatus('/bin/ls')
51   '-rwxr-xr-x  1 root        13352 Oct 14  1994 /bin/ls'
52
t68+ 
69+.. seealso::
70+ 
71+   Module :mod:`subprocess`
72+      Module for spawning and managing subprocesses.
73+ 
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op