本文介绍了从python执行时,如何打印和捕获7zip的%进度标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当7zip从命令行运行时,它将使用一系列'%'符号打印进度条。

When 7zip runs from the command line, it will print a progress bar using a series of '%' symbols.

我想捕获并打印从Python内部执行7zip时,此进度条。
我该怎么做?

I'd like to both capture and print this progress bar when executing 7zip from within Python.How do I do this?

我当前正在使用的Python代码:

The Python code I'm currently using:

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


推荐答案

来自(强调我的意思):

From communicate (emphasis mine):

请考虑使用代替:

Consider using poll instead:

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)
while True: # Feeling fancy?  add a timeout condition here...
    if pipe.poll():
        break
    # consider reading from stdin and printing as your needs indicate

这篇关于从python执行时,如何打印和捕获7zip的%进度标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 07:25