原來的代碼:subprocess.Popen(cmd,shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE),運作到這一行代碼的時候,報error : [WinError 6] 句柄無效錯誤。經過分析發現,少了stderr=subprocess.PIPE這一句代碼。
修改過的代碼 subprocess.Popen(cmd,shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE),加上 stderr=subprocess.PIPE後執行正常。