如何抑制7zip详细输出,但提取状态以百分比表示?

问题描述 投票:-1回答:1

7zip提取的示例输出如下:


Scanning the drive for archives:
1 file, 9770776 bytes (9542 KiB)

Extracting archive: tools\StrawberryPerl.7.exe
--
Path = tools\StrawberryPerl.7.exe
Type = 7z
Offset = 162816
Physical Size = 9607960
Headers Size = 11687
Method = LZMA:24m BCJ2
Solid = +
Blocks = 2

 78% 602 - perl\lib\auto\Module\Pluggable\.packlistProcess SpawnPoolWorker-6:

我的问题是,如何将其抑制为仅获得提取百分比(78% 602 - perl\lib\auto\Module\Pluggable\.packlistProcess SpawnPoolWorker-6:)?

我发现了一些抑制冗长输出的答案,例如:

  1. >NUL:添加到bat命令的末尾,这将完全禁止显示消息。
  2. 在Python中将subprocess.Popenstdout=PIPEstderr=PIPE一起使用,再次抑制了所有消息。
  3. 在bat命令中使用findstr /b /r /c:"\<Everything is Ok",它将基于给定的字符串进行过滤。在这里,我尝试使用类似于\d+\%的正则表达式,但并没有真正的帮助。如您所见,我不擅长批处理脚本。任何建议将不胜感激!
python-3.x batch-file subprocess 7zip
1个回答
0
投票

尝试使用以下方法管道输出:

[7z command] | findstr /rc:"[0-9][%]"
© www.soinside.com 2019 - 2024. All rights reserved.