Xah Lee wrote:
>Python Doc Problem Example: os.system
>
>Xah Lee, 2005-09
>
>today i'm trying to use Python to call shell commands. e.g. in Perl
>something like
>
>output=qx(ls)
>
>in Python i quickly located the the function due to its
>well-named-ness:
>
>import os
>os.system("ls")
>
>
>however, according to the doc
>http://www.python.org/doc/2.4/lib/os-process.html the os.system()
>returns some esoteric unix thing, not the command output.
>
"""
*system*( command)
Execute the command (a string) in a subshell. This is implemented by
calling the Standard C function system(), and has the same
limitations. Changes to |posix.environ|, |sys.stdin|, etc. are not
reflected in the environment of the executed command.
On Unix, the return value is the exit status of the process encoded
in the format specified for wait(). Note that POSIX does not specify
the meaning of the return value of the C system() function, so the
return value of the Python function is system-dependent.
On Windows, the return value is that returned by the system shell
after running command, given by the Windows environment variable
COMSPEC: on *command.com* systems (Windows 95, 98 and ME) this is
always |0|; on *cmd.exe* systems (Windows NT, 2000 and XP) this is
the exit status of the command run; on systems using a non-native
shell, consult your shell documentation.
Availability: Unix, Windows.
"""
Yup. Nothing more esoteric than a process's exit status. That's one of
those really tricky jargons that computer scientist idiots like to throw
around. You've got to watch out for those.
>The doc
>doesn't say how to get the output of the command.
>
>by chance someone told me that in python 2.4 the os.system is
>supplanted by subprocess.call(), but this isn't mentioned in the doc!
>
>
I'm presuming you mean in the os.system docs as you mention below that
you found such documentation.
>upon finding the new doc location
>http://www.python.org/doc/2.4/lib/module-subprocess.html i'm told that
>this module replaces:
>
>os.system
>os.spawn*
>os.popen*
>popen2.*
>commands.*
>
>
>interesting.
>
"""
6.8 subprocess -- Subprocess management
New in version 2.4.
The subprocess module allows you to spawn new processes, connect to
their input/output/error pipes, and obtain their return codes. This
module intends to replace several other, older modules and functions,
such as:
os.system
os.spawn*
os.popen*
popen2.*
commands.*
"""
Yeah. There's a really tricky word up there in the beginning of the
subprocess doc. "intends". In this context, it means that it is
currently the plan of the Python developers to replace said modules with
the subprocess module, *however*, that has not totally come about now.
If the doc had said, "This module *has replaced* several others", then I
would have to agree with you that the stated module docs should be
updated to reflect the fact that they have been deprecated.
> Since i'm not Python expert
>
Really?
>, i like to look at these. But
>fuck, the incompetent doc gives ample gratis links to OpenSource this
>or that or author masturbation
>
OK - I just scanned through the subprocess module docs and I really
don't see where you're getting this from. I'll just chalk the former up
to your bad experience with the regular expression module docs referring
to the book "Mastering Regular Expressions." And since you're quite the
linguistic scholar, I'll chalk up the latter to your unique construction
of the book title I just cited.
> links to remote book i don't really care
>about, but here there's no link.
>
>Problem summary:
>
>* does not focus on the task users need to do. Instead, the doc is
>oriented towards tech geeking.
>
>
Are you talking about the subprocess docs? If so, I'd like to see an
example of what you're talking about. Subprocess docs seem really
straightforward, terse, and to the point.
>* does not inform the reader at the right place where a new function is
>replacing the old.
>
>
I would leave it in the hands of the Python doc maintainers what to do
with this since subprocess hasn't yet totally replaced the other modules.
>* does not provide relevant cross-links. (while provding many
>irrelevant links because of OpenSource or Tech Geeking fanaticism)
>
>
I'd really like to see what you're talking about here. I just went
through the subprocess docs *again* and I don't see *any* links to any
other open source anything and I don't see any "tech geeking" to use
your jar