一、定义
执行命令的模块类似于OS
二、实例
import subprocess res=subprocess.Popen(r'deeddddir D: 4-视频录制存放目录python18期day7xml模块', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) print('=================>',res) print('-========>',res.stdout.read()) print('-========>',res.stderr.read().decode('gbk')) print('-========>',res.stderr.read().decode('gbk')) print('-========>',res.stderr.read().decode('gbk')) print('-========>',res.stderr.read().decode('gbk')) #dir file_path | findstr xml$ 赋于管道 res1=subprocess.Popen(r'dir D: 4-视频录制存放目录python18期day7xml模块', shell=True, stdout=subprocess.PIPE,) # stdin=res1.stout 把上边的结果赋与 res2=subprocess.Popen(r'findstr xml$', shell=True, stdin=res1.stdout, stdout=subprocess.PIPE,) print(res2.stdout.read().decode('gbk'))