做用:用于执行系统命令:1.返回执行结果,2返回执行状态码shell
经常使用方法:windows
run 返回一个表示执行结果的对象函数
call 返回的执行的状态码编码
总结: subprocess的好处是能够获取指令的执行结果code
subprocess执行指令时 能够在子进程中 这样避免形成主进程卡死对象
import subprocessblog
res1=subprocess.Popen(r'dir C:\Users\Administrator\PycharmProjects\test\函数备课',shell=True,stdout=subprocess.PIPE)进程
res=subprocess.Popen('findstr test*',shell=True,stdin=res1.stdout, stdout=subprocess.PIPE)test
print(res.stdout.read().decode('gbk'))#subprocess使用当前系统默认编码,获得结果为bytes类型,在windows下须要用gbk解码import