Extracting a 7-Zip file "silently" - command line option

Viewed 69959

I want to extract a 7-Zip archive in a Python script. It works fine except that it spits out the extraction details (which is huge in my case).

Is there a way to avoid this verbose information while extracting? I did not find any "silent" command line option to 7z.exe.

My command is

7z.exe -o some_dir x some_archive.7z
13 Answers

7-zip has not such an option. Plus the lines printed at each file compressed are supposed to display at the same spot without newline, erasing the previous one, which has a cool effect. Unfortunatly, in some contexts (Jenkins...) it produced several lines ☹️ flooding the console.

NUL (windows) is maybe one solution.

7-zip.exe -o some_dir x some_archive.7z>NUL

Examining 7zip source I found hidden -ba switch that seems to do the trick. Unfortunately it is not finished. I managed to make it work with several modifications of sources but it's just a hack. If someone's interested, the option variable is called options.EnableHeaders and changes are required in CPP/7zip/UI/Console/Main.cpp file. Alternatively you can poke 7Zip's author to finish the feature in tracker. There are several requests on this and one of them is here.

To show just the last 4 lines...

7z x -y some_archive.7z | tail -4

gives me:

Everything is Ok

Size:       917519
Compressed: 171589

The switch -y is to answer yes to everything (in my case to override existing files).

On Unix-like operating systems (Linux, BSD, etc.) the shell command 7z ... >/dev/null will discard all text written by 7z to standard output. That should cover all the status/informational messages written by 7z.

It seems that 7z writes error messages to standard error so if you do >/dev/null, error messages will still be shown.

As told by Fr0sT above, -ba switch outputs only valid things (at least in list option on which I was trying). 7z.exe l archive_name.zip

7z.exe l -ba archive_name.zip

made great difference, esp for parsing the output in scripts. There is no need to modify anything, just use -ba switch in version19. This was also told bysomeone above. I'm putting as answer as I can't comment.

Related