Solved

How to get the output of 7zip piped to another program

Posted on 2009-04-05
3
2,470 Views
Last Modified: 2013-12-26
Hello Community,

I'm using Gentoo Linux and try to write a bash script that compresses a directory using 7zip. While compressing the script should show the progress using the 'dialog' tool.

First of all I count the number of files in that directory using 'find' and 'wc'. That's easy. After that I start 7zip to put the files in that directory into an archive. Until now, there is now problem. 7zip writes every file it processes to stdout and I can see it compressing file after file. The problem is that the shell seems to store the output when I try to pipe it to another process.

Simple Example:
7z a -bd archive.7z <dir-to-backup> | while read line ; do echo "${line}" ; done

When I execute this little script, I see nothing at first... but after 7zip has compressed some files all output is done at one go. After that there is no output for a certain time. 7zip works and consumes a lot of cpu time, but the output seems to be buffered in the pipe or somewhere else. After some time, I guess when the pipe is running full, 7zip's output becomes visible.

Neither zip nor tar does behave in that strange way. Their output can be seen line after line...

Does anyone know how I can solve that problem?
0
Comment
Question by:Metacrawler
3 Comments
 
LVL 7

Accepted Solution

by:
Morne Lategan earned 250 total points
ID: 24070912
Got the same on my side on both debian and Ubuntu. Tried to run it through pv which is a utility to do exactly what you are doing with progress:

7z a /tmp/m.7z <backupdir> | pv -s `find <backupdir> | wc -l` -l -n

pv also just gets to a point and then returns the same progress percentage for a long period of time before resuming.

Same happens with ksh, so my guess is that you'll have to contact the 7z developers and ask them to change the buffering behavior.

0
 
LVL 43

Expert Comment

by:ravenpl
ID: 24070918
Correct, 7z seems buffering stdout if it's not a terminal (man isatty).
0
 

Author Closing Comment

by:Metacrawler
ID: 31566721
Thank you very much. That was exactly what I was looking for. It works like a charm :-)
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question