python学习——python中执行shell命令
这里介绍一下python执行shell命令的四种方法:
1、os模块中的os.system()这个函数来执行shell命令
>>> os.system('ls')
anaconda-ks.cfg install.log install.log.syslog send_sms_service.py sms.py
0
```注,这个方法得不到shell命令的输出。
2、popen()#这个方法能得到命令执行后的结果是一个字符串,要自行处理才能得到想要的信息。
import os
str = os.popen(“ls”).read()
a = str.split(“n”)
for b in a:
print b