---
title: "python执行shell命令的四种方法"
author: "f002489"
date: "2016-12-28T22:36:18Z"
tags: ["Python"]
categories: ["编程语言"]
slug: "python-shell"
draft: false
lastmod: "2016-12-28T22:36:18Z"
id: 2347945
url: "https://f002489.iteye.com/blog/2347945"
---

#!/usr/bin/env python    
# -*- coding: utf-8 -*-   
import os  
import platform  
import subprocess  
import commands  
def subproc():  
    print "系统进程数："  
    subprocess.call("ps -ef|wc -l",shell=True)  
def os_popen():  
    print "IP地址："  
    os1 = platform.system()  
    if os1 == "Linux":  
           print os1  
           ip1 =os.popen("/sbin/ifconfig eth0|grep 'inet addr'").read().strip().split(":").split()  
           print "\033