2014年7月27日日曜日

開発環境

Head First C ―頭とからだで覚えるCの基本(David Griffiths (著)、Dawn Griffiths (著) 中田 秀基(監訳)(翻訳)、木下 哲也 (翻訳)、オライリージャパン)の9章(プロセスとシステムサービス: 限界を超える)、エクササイズ(p.409)をpythonで考えてみる。

エクササイズ(p.409)

コード(BBEdit, Emacs)

sample409.py

#!/usr/bin/env python3
#-*- coding: utf-8 -*-

import os
import sys

try:
    os.execl('/sbin/ifconfig', '/sbin/ifconfig')
except:
    try:
        os.execlp('ipconfig', 'ipconfig')
    except Exception as err:
        print('ipconfigを実行出来ません。{0}'.format(err))
        sys.exit(1)

print('終了')

入出力結果(Terminal, IPython)

$ ./sample409.py 
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
 options=3<RXCSUM,TXCSUM>
 inet6 ::1 prefixlen 128 
 inet 127.0.0.1 netmask 0xff000000 
 inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1 
 nd6 options=1<PERFORMNUD>
gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280
stf0: flags=0<> mtu 1280
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
 options=10b<RXCSUM,TXCSUM,VLAN_HWTAGGING,AV>
 ether c8:2a:14:0c:f6:8c 
 inet6 fe80::ca2a:14ff:fe0c:f68c%en0 prefixlen 64 scopeid 0x4 
 inet 169.254.135.15 netmask 0xffff0000 broadcast 169.254.255.255
 nd6 options=1<PERFORMNUD>
 media: autoselect (1000baseT <full-duplex,flow-control>)
 status: active
en1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
 ether e0:f8:47:2f:38:ce 
 inet6 fe80::e2f8:47ff:fe2f:38ce%en1 prefixlen 64 scopeid 0x5 
 inet 192.168.0.5 netmask 0xffffff00 broadcast 192.168.0.255
 nd6 options=1<PERFORMNUD>
 media: autoselect
 status: active
en2: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
 options=60<TSO4,TSO6>
 ether d2:00:1c:3c:0c:20 
 nd6 options=1<PERFORMNUD>
 media: autoselect <full-duplex>
 status: inactive
fw0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 4078
 lladdr 70:cd:60:ff:fe:c3:c0:c2 
 nd6 options=1<PERFORMNUD>
 media: autoselect <full-duplex>
 status: inactive
p2p0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 2304
 ether 02:f8:47:2f:38:ce 
 media: autoselect
 status: inactive
vmnet1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
 ether 00:50:56:c0:00:01 
 inet 172.16.130.1 netmask 0xffffff00 broadcast 172.16.130.255
vmnet8: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
 ether 00:50:56:c0:00:08 
 inet 172.16.115.1 netmask 0xffffff00 broadcast 172.16.115.255
utun0: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> mtu 1380
 inet6 fe80::7994:f032:745c:3cdb%utun0 prefixlen 64 scopeid 0xb 
 inet6 fd0f:8fd1:9ac4:ae59:7994:f032:745c:3cdb prefixlen 64 
 nd6 options=1<PERFORMNUD>
$

0 コメント:

コメントを投稿