LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 03-12-2006, 08:09 AM   #1
bjdea1
Member
 
Registered: Oct 2003
Posts: 37

Rep: Reputation: 15
How do you read gzip output from 'C' program?


Hi,
I'm coding in "C" and I am using the PIPE method to invoke the running of a gzip command from another program. Its a backup program and part of the program is to verify the integrity of the gzipped backup file. To do this I try to execute the command:
"gzip -vt <backupfile>.tar.gz" via opening a PIPE.
The pipe opens and executes this command fine however the resulting output doesn't get sent back up the PIPE to my program, it just gets printed out in the shell. E.g. "<backupfile>.tar.gz: OK" shows on the screen, but my program doesn't get this output sent back to it. So my program never knows the result of this test. How can I get my program to read this shell outputted result?

Any help greatly appreciated.

Last edited by bjdea1; 03-12-2006 at 08:10 AM.
 
Old 03-12-2006, 10:36 AM   #2
randyding
Member
 
Registered: May 2004
Posts: 552

Rep: Reputation: 30
What exactly is your "PIPE method"? Are you using popen()? Show an example of what does not work.
 
Old 03-12-2006, 05:24 PM   #3
bjdea1
Member
 
Registered: Oct 2003
Posts: 37

Original Poster
Rep: Reputation: 15
Thanks for taking itme to respond

I found a solution - help from a guy on cprogramming.com boards - but thanks for taking time to read my problem and taking an interest.

Yes I was using popen();

I was told that gzip outputs to stderr instead of stdout. So in my popen command I was advised to change it to :

sprintf(command, "gzip -vt %s.tar.gz 2>&1", backupfilename);

Added the "2>&1" and that redirects stderr output to stdout, AND IT WORKS !!!!!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
tar and gzip - how do i point to a output directory RedHat123 Linux - Newbie 4 04-20-2011 10:48 AM
read gzip files with Mozilla? lugoteehalt Linux - Software 9 11-17-2005 04:27 AM
Solaris 8 gzip issues- cannot gzip -d lynx sixosix Solaris / OpenSolaris 4 03-13-2005 03:17 PM
C function to execute a program and return the output of the program ryan.n Programming 4 08-14-2004 10:11 PM
Read the output from a pipe with bash ? fluppi Linux - Software 3 01-13-2004 12:59 PM


All times are GMT -5. The time now is 03:20 PM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration