LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   gunzip complains "Unexpected End-of-file" when C prog's output is fed to it in bash (https://www.linuxquestions.org/questions/linux-software-2/gunzip-complains-unexpected-end-of-file-when-c-progs-output-is-fed-to-it-in-bash-732489/)

daton007 06-12-2009 10:08 AM

gunzip complains "Unexpected End-of-file" when C prog's output is fed to it in bash
 
Hi,
I have a C program (a.out) which outputs a file in the stdout. Then I pipe the output of this C program to gunzip to decompress the data. The data output by the C program was previously compressed with gzip. My shell script looks like this:

#!/bin/sh

./a.out | gunzip -dc > new_file

But, when I try to run this script from command line, I get the following error:

gunzip: stdin: unexpected end of file

In my C program, I output the file with:

fwrite(array, sizeof(unsigned chat), size, stdout);
fflush(stdout);
fclose(stdout);

I don't understand why still gunzip complains about unexpected end of file. My search for the answer revealed that the file pointer to which the C program writes data (in this case stdout), must be closed explicitly. I have already done so... Can anyone please put some light on what I might be doing wrong?

--Thanks in advance.

norobro 06-13-2009 01:09 PM

I suppose there is a reason that you are running a script to execute a c program that reads a zipped file and pipes it gunzip. Seems like a lot of work!
Why not just run:
Code:

gunzip -c filename > new_file
Does the above command give you an error?


All times are GMT -5. The time now is 05:33 PM.