使用 subprocess 获取命令返回值以及命令执行的状态
2019-03-01 本文已影响0人
w也不知道
# cat cmd.py
#########################################################################
# -*- coding:utf-8 -*-
# File Name: cmd.py
# Author: lcs
# Mail: liuchengsheng95@qq.com
# Created Time: 2019-03-01 11:29:21
#########################################################################
#!/usr/bin/python3
import subprocess,os
status,res = subprocess.getstatusoutput('ls /root')
print("status is %d" % status)
for d in res.split('\n'):
f = '/root/' + d
if os.path.isdir(f):
print("%s is dir!" % f)
else:
print("%s is not dir!" % f)

