newb Q

Steffen Ries steffen.ries at sympatico.ca
Sat Jul 22 08:10:19 EDT 2000


Toy <gee308 at mediaone.net> writes:

> Thanks for showing me how to do that.  I tried to edit something, but it
> didn't work, I'll show you:
> 
> 
> def getMyAddr():
>   object = raw_input(Which device is connect to the internet(i.e. ppp0, eth0,
> ne3: ")
>   p=os.popen("/sbin/ifconfig",object)
> 
> Is it possible to do that?  Will it work with os.system?  What are the
> differences bewteen using os.popen and os.system?  Thanks for your time.
> BTW, I only compared OpenBSD 2.7, Linux 2.2.15, and FreeBSD 4.0, but it seems
> if you do the string search  on ifconfig with find text on 1 line beginning
> with inet and ending with mask, It looks like you can get the IP from those 3
> machines.(of coure I still can't write some code to actually do it).  Thanks
> again.
> Jason Toy
> 

popen() expects as the first parameter a command line. The optional
second parameter is a mode string, either "r" for reading or "w" for
writing.

You want:
  p=os.popen("/sbin/ifconfig %s" % object)

Both os.popen() and os.system() run commands through the system
shell. The difference is os.popen() returns a pipe for reading results
or writing input to the command. os.system() just runs the command.

-- 
steffen.ries at sympatico.ca	<> Gravity is a myth -- the Earth sucks!



More information about the Python-list mailing list