做用:用於執行系統命令: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