[Tutor] ipconfig on a MacOS X

Pijus Virketis pijus@virketis.com
Sat Mar 22 00:55:02 2003


Reggie,

Thank you for your pointer. As it happens, MacPython os module does not 
seem to have popen() either. But the terminal Python does, and I 
successfully wrote my script the way you suggested. I would still love 
to hear from someone wiser in the ways of the Mac OS X what the 
equivalent approach to executing system calls is from MacPython.

-P

On Friday, March 21, 2003, at 10:10 AM, Reggie Dugard wrote:

> In answer to your first question, you can use os.popen:
>
>>>> import os
>>>> ip = os.popen("ipconfig getifaddr en0").read()
>>>> print ip
>
> os.popen returns a file object which, in this case, I simply read into
> ip.  This should work in any version of python.  As to the "split" you
> mention, I know nothing about the Mac, but I do know that David Beazley
> noted in his book "Python Essential Reference" (excellent reference
> book, by the way) that os.system is only available on UNIX and Windows.
>
> On Thu, 2003-03-20 at 23:18, Pijus Virketis wrote:
>
>> So, I would like to ask two questions: how do I grab the output in
>> terminal Python? And, how do I accomplish the whole task in MacPython?
>> How come there is this schizophrenic split between the two Pythons? (I
>> guess that's a third question, we can all fondly remember the Spanish
>> Inquisition at this point :)).
>>
>> Thank you!
>>
>> Pijus
>
> -- 
> Reggie
>
>