capturing the output of external commands
Paul Miller
pwmiller1 at adelphia.net
Sun Jul 25 17:22:46 EDT 2004
Avi Kak <kak at purdue.edu> wrote in message news:<0pg7g0tjoe0c9075kqdg7pjvlnlkqodf7k at 4ax.com>...
> Is there a Python function in any of the
> standard-distribution modules that does
> what the backticks do in Perl?
>
> I want to run an external command and I'd
> like its output to be captured directly
> in my Python script in the form of a string
> object.
You can fake it by redirecting the output of whatever external command
you want to run to a file, and then reading the file into a string.
It seems like kind of a hack (how does Perl's implementation actually
work for this, though?), but it will work. Package it up as a
function and you're set.
More information about the Python-list
mailing list