Re: bunzip2 when exec()-ed from perl script outputs garbage data.

From: Cameron Kerr (cameron.kerr_at_paradise.net.nz)
Date: 02/02/04

  • Next message: elastic: "simple timer for win32, solaris and linux"
    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!
    

  • Next message: elastic: "simple timer for win32, solaris and linux"

    Relevant Pages

    • Re: COBOL for utility program under Linux.
      ... CGI generally is reading from or writing to STDIN and STDOUT. ... Woo, the seven years since I last did anything in COBOL has apparently taken ...
      (comp.lang.cobol)
    • Re: question about /proc/<PID>/mem in 2.4 (fwd)
      ... > things doesn't prevent the program from reading it's own address space. ... > and this program reading stdin. ... http://www.openwall.com - bringing security into open computing environments ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • Re: how to speed up smalltalk file I/O
      ... Looks like the problem is that you're reading from stdin, ... Integers (after the number it "eats" the non-numeric character and then ... thing displayNl. ... s:= FileStream stdin. ...
      (comp.lang.smalltalk)
    • Re: problems mixing direct char i/o with handle i/o
      ... I've tried resetting the input prior to reading from STDIN but it made ... I tried DOS function INT 21h AH=0Ch AL=00h. ...
      (comp.os.msdos.programmer)
    • Re: Parsing form POST without CGI.pm on Win32
      ... Using your code (or any other code I got from books, ... deal with the STDIN all produce the same. ... Your code died "Reading of posted data failed." ... use strict; ...
      (comp.lang.perl.misc)