[英]why does python.subprocess hang after proc.communicate()?
[英]Output of proc.communicate() does not format newlines in django python
我有一個使用通信的子進程來獲取輸出並將其保存到我的數據庫:
p = Popen([str(pre_sync), '-avu', str(src), str(dest)], stdout=PIPE)
syncoutput = p.communicate()
check.log = syncoutput
一切正常,但通信的輸出如下所示:
('sending incremental file list\n\nsent 89 bytes received 13 bytes 204.00 bytes/sec\ntotal size is 25 speedup is 0.25\n', None)
全部在一行中插入“\\ n”。 有沒有辦法讓它在一個新行中打印每一行? 提前致謝。
syncoutput,sync_error = p.communicate()
print(syncoutput)
p.communicate()返回一個2元組,由stdout和stderr的輸出組成。 打印2元組時,您會看到\\n
字符。 當您打印字符串(新的syncoutput
)時,您將獲得格式化文本。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.