1
我希望能夠使用Popen.communicate
,並有標準輸出記錄到文件中(除了從communicate()
返回通信的Python subprocess.Popen通過管道
此我想要做什麼 - 但真的是這樣嗎一個好主意?
cat_task = subprocess.Popen(["cat"], stdout=subprocess.PIPE, stdin=subprocess.PIPE)
tee_task = subprocess.Popen(["tee", "-a", "/tmp/logcmd"], stdin=cat_task.stdout,
stdout = subprocess.PIPE, close_fds=True)
cat_task.stdout = tee_task.stdout #since cat's stdout is consumed by tee, read from tee.
cat_task.communicate("hello there")
('hello there', None)
與此有關的問題,尋找溝通的IMPL它看起來不錯,但有沒有更好的辦法?