如何讓我的 write() 函數接受我的 stdout = subprocess.PIPE 輸出?我不斷收到類型錯誤問題。這是我的代碼:with open("logger.txt","w") as fobj: baby = subprocess.Popen('bash arguments', stdout = subprocess.PIPE, shell = True) fobj.write(baby.communicate())我得到類型錯誤我試過這個,沒有錯誤,但文件總是空的with open("logger.txt","w") as fobj: baby = subprocess.Popen('bash arguments', stdout = subprocess.PIPE, shell = True) baby.communicate()誰能幫我?謝謝
1 回答

慕容708150
TA貢獻1831條經驗 獲得超4個贊
如果您只想將腳本的輸出寫入fobj,
with open("logger.txt","wb") as fobj:
subprocess.check_call('bash arguments', stdout=fobj, shell=True)
添加回答
舉報
0/150
提交
取消