#subprocess模块:启子进程模块
import subprocess
obj=subprocess.Popen('tasklist',shell=True,  #shell=True调用命令解释器来解释前面的命令,发信号并不执行
                 stdout=subprocess.PIPE,      #PIPE管道
                 stderr=subprocess.PIPE,      #放入报错信息
                 )
print(obj.stdout.read().decode('gbk'))  #只能取一次值,取出格式是b格式

import subprocess
obj=subprocess.Popen('list',shell=True,
                 stdout=subprocess.PIPE,    #PIPE管道
                 stderr=subprocess.PIPE,    #放入报错信息
                 )
print(obj.stderr.read().decode('gbk'))     #只能取一次值,取出格式是b格式

import subprocess
obj=subprocess.Popen('ps aux |grep python',shell=True,
                 stdout=subprocess.PIPE,    #PIPE管道
                 stderr=subprocess.PIPE,    #放入报错信息
                 )
print(obj.stdout.read())

import subprocess   #同上
obj1=subprocess.Popen('ps aux ',shell=True,
                 stdout=subprocess.PIPE,    #PIPE管道
                 stderr=subprocess.PIPE,    #放入报错信息
                 )
obj2=subprocess.Popen('grep python ',shell=True,
                 stdin=obj1.stdout,
                 stdout=subprocess.PIPE,    #PIPE管道
                 stderr=subprocess.PIPE,    #放入报错信息
                 )
print(obj2.stdout.read())