subprocess模块

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('\n') for i in line[1:-1]: i = i.split() print(i[0],i[4].replace('%','')) check_file()

  

posted @ 2019-03-17 20:42  superniao  阅读(153)  评论(0编辑  收藏  举报