一,使用 subprocess + shell 命令实现
二,使用 Psutil 实现 (用python实现系统相关的命令行功能)
一,使用 subprocess + shell 命令实现
# -*- coding=utf-8 -*-
# Created Time: 2016年12月16日 星期五 16时53分27秒
# File Name: 02_os_disk_info.py
"""
获取磁盘信息
"""
import subprocess
def get_one(path):
# 指定单位 -BK -BM -BG
df = subprocess.Popen(['df', '-BG', path], stdout=subprocess.PIPE)
output = df.communicate()[0]
print output
device, size, used, available, percent, mountpoint = \
output.split('\n')[1].split()
print 'device: ', device
print 'seize: ', size
print 'used: ', used
print 'available: ', available
print 'percent: ', percent
print 'mountpoint: ', mountpoint
print '########################