1、 os.system
os.system('ls -l')
执行没有返回值,无法判断命令是否成功执行,以及输出结果,适用于创建文件、文件夹场景
2、popen()
import os
str = os.popen("ls").read()
a = str.split("\n")
for b in a:
print(b)
解析命令输出结果,通过换行符进行解析
3、 commands
import commands
a,b = commands.getstatusoutput('ls')
#a 表示命令执行状态,所有非0值都表示错误,
#b 表示输出结果的字符串
a = commands.getstatusoutput('ls -l')
b = commands.getoutput('ls -l')


7096

被折叠的 条评论
为什么被折叠?



