Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2009-04-05
3
Medium Priority
?
2,618 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 7

Accepted Solution

by:
Morne Lategan earned 1000 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

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

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

SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Suggested Courses

715 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