python内置模块(commands、sys)
1、commands模块只使用与linux的shell模式下a)commands.getoutput(cmd)[root@localhost ~]# cat a.py#!/usr/bin/env python#-*- coding:utf-8 -*-import commandscmd = 'ls /home/admin'a = commands.getoutput(cmd)pr
·
1、commands模块只使用与linux的shell模式下
a) commands.getoutput(cmd)
[root@localhost ~]# cat a.py
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import commands
cmd = 'ls /home/admin'
a = commands.getoutput(cmd)
print(type(a))
print(a)
结果:
[root@localhost ~]# python a.py
[root@localhost ~]# cat c.py
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import commands
cmd = 'ls /home/admin'
c = commands.getstatusoutput(cmd)
print(type(c))
status, output = commands.getstatusoutput(cmd)
print(status)
print(output)
print(type(output))
结果:
[root@localhost ~]# python c.py
更多推荐
已为社区贡献2条内容
所有评论(0)