Boston Linux & Unix (BLU) Home | Calendar | Mail Lists | List Archives | Desktop SIG | Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings
Linux Cafe | Meeting Notes | Blog | Linux Links | Bling | About BLU

BLU Discuss list archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Perform other functions while untarring file using "system" command in a C program



On Wed, 31 Jan 2001, zoqix wrote:

> Hi all, 
> I'm using the "system" command to do an untarring of a file.tar.gz file
> in my C program. However, I would like to display some status
> information like "10 % Completed". I've written some code to calculate
> the percentage. However, the code could only be runned after the
> "system" command finished untarring my zipped file. e.g.   
> 
> system("tar zxf file.tar.gz");
> do
> {
> printf("%d %% Completed", percent);
> }while (!finished) 
> 
> Therefore, the printf will always print 100 % Completed. Is there any
> way to let the unzipping continue at background and return to print the
> completion status?
> 

A look through the info files for GNU tar shows the following:

	`--checkpoint'
		This option directs `tar' to print periodic checkpoint
		messages as it reads through the archive.  Its intended
		for when you want a visual indication that `tar' is still
		running, but don't want to see `--verbose' output.

It doesn't give a percentage, and it's not immediately clear what the
number it does give actually represents, but it's probably a good starting
point.

To use its output, you'd have to replace the "system" call with a call to
popen that reads from the stdout of the "tar" process. You'd also want to
change the buffering of data in the pipe so you can immediately read the
output from tar at the newline, rather than waiting for a complete block
to be buffered.

--
John Abreau / Executive Director, Boston Linux & Unix 
ICQ#28611923 / AIM abreauj / Email jabr at blu.org

-
Subcription/unsubscription/info requests: send e-mail with
"subscribe", "unsubscribe", or "info" on the first line of the
message body to discuss-request at blu.org (Subject line is ignored).




BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!



Boston Linux & Unix / webmaster@blu.org