Grabbing a command's output was Re: dns reverse look up with python ?
Remco Gerlich
scarblac at pino.selwerd.nl
Wed Jan 10 04:26:23 EST 2001
Joel Ricker <joejava at dragonat.net> wrote in comp.lang.python:
> When I saw this question posted last night, I started to answer it the same
> way I did it in Perl. I needed to do a reverse lookup myself in a project I
> was doing. I couldn't make heads or tails of the perl modules that can do
> this so I finally figured out how to do this as a os command with nslookup.
> Basically I was looking up the IP address reported by the web server to see
> if its me or not and lock out everyone else for the time being. With perl
> you do system commands like this:
>
> $Result = `nslookup 127.0.0.1`
>
> and $Result will contain the results of the command. But what I found in
> the Python reference was os.system("command") which returned only a value
> that reports if the command was successful or not. What is the Python way
> of running command and have the actual results of the command returned?
os.popen("command")
returns a filelike object that you can read from.
--
Remco Gerlich
More information about the Python-list
mailing list