使用 subprocess 获取命令返回值以及命令执行的状态
#!/usr/bin/python3import 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)
https://www.jianshu.com/p/1c080b8458e4
页:
[1]