proc.communicate() 的输出不会在 django python 中格式化换行符
我有一个使用communicate来获取输出并将其保存到我的数据库的子进程:
p = Popen([str(pre_sync), '-avu', str(src), str(dest)], stdout=PIPE)
syncoutput = p.communicate()
check.log = syncoutput
一切正常,但是communicate的输出看起来像这样:
('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”。有没有办法让它在新行中打印每一行?提前致谢。
I have a subprocess using communicate to get the output ans saving it to my database:
p = Popen([str(pre_sync), '-avu', str(src), str(dest)], stdout=PIPE)
syncoutput = p.communicate()
check.log = syncoutput
It all works fine, but the output from communicate looks like this:
('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)
All in a single line and with the "\n" inserted. Is there a way I can make it print each line in a new line? Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
p.communicate() 返回一个 2 元组,组成stdout 和 stderr 的输出。当您打印二元组时,您会看到
\n
字符。当您打印字符串(新的syncoutput
)时,您将获得格式化文本。p.communicate() returns a 2-tuple, composed of the output from stdout and stderr. When you print the 2-tuple, you see the
\n
characters. When you print the string (of the newsyncoutput
), you will get formatted text.