Re: bunzip2 when exec()-ed from perl script outputs garbage data.
From: Cameron Kerr (cameron.kerr_at_paradise.net.nz)
Date: 02/02/04
- Previous message: Joe Smith: "Re: bunzip2 when exec()-ed from perl script outputs garbage data."
- In reply to: Thomas Covello: "bunzip2 when exec()-ed from perl script outputs garbage data."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 2 Feb 2004 14:46:01 +1300
[Followup-To set to COL]
In comp.os.linux Thomas Covello <pmjcovello@shaw.ca> wrote:
> read STDIN, $header_bytes, 4 or die "Trouble reading input: $!";
> if ($header_bytes eq $GZIP_HEADER) {
> exec "gunzip -f";
> die "gunzip doesn't exist or can't be accessed: $!";
> } elsif ($header_bytes eq $BZIP_HEADER) {
> exec "bunzip2 -f";
> die "bunzip2 doesn't exist or can't be accessed: $!";
> } else { die "Not a proper zip file or unsupported zip format." }
You have a fundamental flaw. You are reading in 4 bytes from stdin, and
then execing gunzip or bunzip, which will read in the data, but it WON'T
get the 4 bytes you've already read in, therefore the header won't be
recognised, and you'll get an error, or something weird.
You need to either find some way of peeking the contents of stdin
(without removing it from the queue (you'll likely need to use sysread),
or don't take the input from stdin. Take it from a file instead, that
Also, if you don't redirect the output of this program, you're going to
get (very likely) binary gibberish being output. But you probably knew
that part already.
-- Cameron Kerr cameron.kerr@paradise.net.nz : http://nzgeeks.org/cameron/ Empowered by Perl!
- Previous message: Joe Smith: "Re: bunzip2 when exec()-ed from perl script outputs garbage data."
- In reply to: Thomas Covello: "bunzip2 when exec()-ed from perl script outputs garbage data."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|