Mercurial > cpython-lru_cache-weakref
annotate Doc/libcommands.tex @ 5817:48b94de85bf3 legacy-trunk
Extensive changes by AMK.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Thu, 17 Jul 1997 16:29:42 +0000 |
| parents | 6a218fa8ba9b |
| children | e16994f3d102 |
| rev | line source |
|---|---|
|
5738
c29fc17d8e4f
Documentation for Lib/commands.py, from Sue Williams.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
1 \section{Standard module \sectcode{commands}} % If implemented in Python |
|
c29fc17d8e4f
Documentation for Lib/commands.py, from Sue Williams.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
2 \stmodindex{commands} |
|
c29fc17d8e4f
Documentation for Lib/commands.py, from Sue Williams.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
3 |
|
c29fc17d8e4f
Documentation for Lib/commands.py, from Sue Williams.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
4 The \code{commands} module contains wrapper functions for \code{os.popen()} |
|
c29fc17d8e4f
Documentation for Lib/commands.py, from Sue Williams.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
5 which take a system command as a string and return any output generated by |
|
c29fc17d8e4f
Documentation for Lib/commands.py, from Sue Williams.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
6 the command, and optionally, the exit status. |
|
c29fc17d8e4f
Documentation for Lib/commands.py, from Sue Williams.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
7 |
|
c29fc17d8e4f
Documentation for Lib/commands.py, from Sue Williams.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
8 The \code{commands} module is only usable on systems which support |
|
c29fc17d8e4f
Documentation for Lib/commands.py, from Sue Williams.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
9 \code{popen()} (currently \UNIX{}). |
|
c29fc17d8e4f
Documentation for Lib/commands.py, from Sue Williams.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
10 |
|
c29fc17d8e4f
Documentation for Lib/commands.py, from Sue Williams.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
11 The \code{commands} module defines the following functions: |
|
c29fc17d8e4f
Documentation for Lib/commands.py, from Sue Williams.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
12 |
|
c29fc17d8e4f
Documentation for Lib/commands.py, from Sue Williams.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
13 \renewcommand{\indexsubitem}{(in module commands)} |
|
c29fc17d8e4f
Documentation for Lib/commands.py, from Sue Williams.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
14 \begin{funcdesc}{getstatusoutput}{cmd} |
|
c29fc17d8e4f
Documentation for Lib/commands.py, from Sue Williams.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
15 Execute the string \var{cmd} in a shell with \code{os.popen()} and return |
|
c29fc17d8e4f
Documentation for Lib/commands.py, from Sue Williams.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
16 a 2-tuple (status, output). \var{cmd} is actually run as |
|
5740
6a218fa8ba9b
Fix LaTeX bug found by examining the docstrings added to commands.py.
Fred Drake <fdrake@acm.org>
parents:
5738
diff
changeset
|
17 \samp{\{\ cmd \} ; 2$>$\$1}, so that the returned output will contain output |
|
5738
c29fc17d8e4f
Documentation for Lib/commands.py, from Sue Williams.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
18 or error messages. A trailing newline is stripped from the output. |
|
c29fc17d8e4f
Documentation for Lib/commands.py, from Sue Williams.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
19 The exit status for the command can be interpreted according to the |
|
c29fc17d8e4f
Documentation for Lib/commands.py, from Sue Williams.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
20 rules for the \C{} function \code{wait()}. |
|
c29fc17d8e4f
Documentation for Lib/commands.py, from Sue Williams.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
21 \end{funcdesc} |
|
c29fc17d8e4f
Documentation for Lib/commands.py, from Sue Williams.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
22 |
|
c29fc17d8e4f
Documentation for Lib/commands.py, from Sue Williams.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
23 \begin{funcdesc}{getoutput}{cmd} |
|
c29fc17d8e4f
Documentation for Lib/commands.py, from Sue Williams.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
24 Like \code{getstatusoutput()}, except the exit status is ignored and |
|
c29fc17d8e4f
Documentation for Lib/commands.py, from Sue Williams.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
25 the return value is a string containing the command's output. |
|
c29fc17d8e4f
Documentation for Lib/commands.py, from Sue Williams.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
26 \end{funcdesc} |
|
c29fc17d8e4f
Documentation for Lib/commands.py, from Sue Williams.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
27 |
|
c29fc17d8e4f
Documentation for Lib/commands.py, from Sue Williams.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
28 \begin{funcdesc}{getstatus}{file} |
|
c29fc17d8e4f
Documentation for Lib/commands.py, from Sue Williams.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
29 Return the output of \samp{ls -ld \var{file}} as a string. This |
|
c29fc17d8e4f
Documentation for Lib/commands.py, from Sue Williams.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
30 function uses the \code{getoutput()} function, and properly escapes |
|
c29fc17d8e4f
Documentation for Lib/commands.py, from Sue Williams.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
31 backslashes and dollar signs in the argument. |
|
c29fc17d8e4f
Documentation for Lib/commands.py, from Sue Williams.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
32 \end{funcdesc} |
|
c29fc17d8e4f
Documentation for Lib/commands.py, from Sue Williams.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
33 |
|
c29fc17d8e4f
Documentation for Lib/commands.py, from Sue Williams.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
34 Example: |
|
c29fc17d8e4f
Documentation for Lib/commands.py, from Sue Williams.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
35 |
|
c29fc17d8e4f
Documentation for Lib/commands.py, from Sue Williams.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
36 \begin{verbatim} |
|
c29fc17d8e4f
Documentation for Lib/commands.py, from Sue Williams.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
37 >>> import commands |
|
c29fc17d8e4f
Documentation for Lib/commands.py, from Sue Williams.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
38 >>> commands.getstatusoutput('ls /bin/ls') |
|
c29fc17d8e4f
Documentation for Lib/commands.py, from Sue Williams.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
39 (0, '/bin/ls') |
|
c29fc17d8e4f
Documentation for Lib/commands.py, from Sue Williams.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
40 >>> commands.getstatusoutput('cat /bin/junk') |
|
c29fc17d8e4f
Documentation for Lib/commands.py, from Sue Williams.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
41 (256, 'cat: /bin/junk: No such file or directory') |
|
c29fc17d8e4f
Documentation for Lib/commands.py, from Sue Williams.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
42 >>> commands.getstatusoutput('/bin/junk') |
|
c29fc17d8e4f
Documentation for Lib/commands.py, from Sue Williams.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
43 (256, 'sh: /bin/junk: not found') |
|
c29fc17d8e4f
Documentation for Lib/commands.py, from Sue Williams.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
44 >>> commands.getoutput('ls /bin/ls') |
|
c29fc17d8e4f
Documentation for Lib/commands.py, from Sue Williams.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
45 '/bin/ls' |
|
c29fc17d8e4f
Documentation for Lib/commands.py, from Sue Williams.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
46 >>> commands.getstatus('/bin/ls') |
|
c29fc17d8e4f
Documentation for Lib/commands.py, from Sue Williams.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
47 '-rwxr-xr-x 1 root 13352 Oct 14 1994 /bin/ls' |
|
c29fc17d8e4f
Documentation for Lib/commands.py, from Sue Williams.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
48 \end{verbatim} |
