python基础之使用os.system来执行系统命令教程Python

印迹发布于:2019-3-9 1030

使用python 的os.system执行系统命令

使用如下方法:

import os
print os.system('ping www.virplus.com')

输出结果:

64 bytes from 104.27.148.191: icmp_seq=0 ttl=245 time=6.798 ms
64 bytes from 104.27.148.191: icmp_seq=1 ttl=244 time=7.561 ms
64 bytes from 104.27.148.191: icmp_seq=1 ttl=246 time=7.161 ms
64 bytes from 104.27.148.191: icmp_seq=1 ttl=245 time=5.123 ms
64 bytes from 104.27.148.191: icmp_seq=1 ttl=248 time=7.146 ms

大部分动作都是由os模块来帮助完成,pythonk中现成的模块功能非常多,这是python的特色

接下来再来做另外一个例子:

import os
print os.system('ifconfig')

执行后可以取出网卡信息,大家也可以用python os.system 来尝试更多的系统命令,方便快捷。



http://www.virplus.com/thread-169.htm
转载请注明:2019-3-9 于 VirPlus 发表

推荐阅读
最新回复 (0)

    ( 登录 ) 后,可以发表评论!

    返回