LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 06-12-2009, 10:08 AM   #1
daton007
LQ Newbie
 
Registered: Jun 2009
Posts: 1

Rep: Reputation: 0
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.
 
Old 06-13-2009, 01:09 PM   #2
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
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?
 
  


Reply

Tags
error


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Backup Script error "line 31: syntax error: unexpected end of file" eswanepoel General 7 12-07-2007 09:28 AM
"gzip: stdin: unexpected end of file" when untaring Niflheim Linux - Newbie 8 11-12-2007 07:05 PM
Simple bash script "unexpected end of line error" snowman81 Programming 11 11-11-2007 09:31 AM
bash "unexpected end of file" script error Runge_Kutta Linux - General 6 05-23-2007 03:36 PM
Can I redirect script output to a file without ">> $LOGFILE" at the end of each line davee Linux - General 1 12-19-2003 05:01 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:51 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration