从python执行时如何打印和捕获7zip的%进度标记? [英] How to print and capture 7zip's % progress markers when executing from python?
问题描述
当 7zip 从命令行运行时,它将使用一系列%"符号打印一个进度条.
我想在从 Python 中执行 7zip 时捕获并打印此进度条.我该怎么做?
我目前使用的 Python 代码:
from subprocess import Popen, PIPEpipe = Popen('7za.exe a -tgzip "e:\backup\sch Testerr 2012 06 23 17-27.gzip" "E:/archiv"' , stdout=PIPE)文本 = pipe.communicate()[0]打印文本
我发现 7za 在重定向 stdout 时会抑制进度输出. When 7zip runs from the command line, it will print a progress bar using a series of '%' symbols. I'd like to both capture and print this progress bar when executing 7zip from within Python.
How do I do this? The Python code I'm currently using:
I found 7za suppress progress output when stdout is redirected. 这篇关于从python执行时如何打印和捕获7zip的%进度标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
所以,我写了一个补丁.
'sopg' 选项即使在 stdout 被重定向或管道传输时也能启用进度输出.https://github.com/photom/p7zip/commit/2baacd6c354fbde19ebc83d185e73f6d9bd62517">$ 7za x -sopg ..7z
from subprocess import Popen, PIPE
pipe = Popen('7za.exe a -tgzip "e:\backup\sch Testerr 2012 06 23 17-27.gzip" "E:/archiv"' , stdout=PIPE)
text = pipe.communicate()[0]
print text
So, I wrote a patch.
'sopg' option enables progress output even when stdout is redirected or piped.
https://github.com/photom/p7zip/commit/2baacd6c354fbde19ebc83d185e73f6d9bd62517$ 7za x -sopg ..7z