output = subprocess.run(['df', '-h'],capture_output=True)
outout.returncode #获取执行的状态码 0为正常
output.stdout.decode() #获取执行结果 默认结果为bytes类型,所需要decode
#!/usr/bin/python37 #-*- coding: utf-8 -*- import subprocess def check_file():
"""检查文件系统""" output = subprocess.run('df -h',shell=True,capture_output=True) file_obj = output.stdout.decode() line = file_obj.split(' ') for i in line[1:-1]: i = i.split() print(i[0],i[4].replace('%','')) check_file()