Hello Monks! I'm trying to write a routine which takes a filehandle of compressed data and returns a filehandle to the uncompressed data. I don't want to use Compress::Zlib because I want to support tzip, bzip2, etc. Here's what I've implemented using open2:
use IPC::Open2; use FileHandle; sub decompress_filehandle { my $fh = shift; $WRITEHANDLE = new FileHandle(); $READHANDLE = new FileHandle(); $procid = open2($READHANDLE,$WRITEHANDLE,'gzip -cd'); #$procid = open2($READHANDLE,$WRITEHANDLE,'c:\progra~1\cygwin\bin\gz +ip.exe -cd'); die "Couldn't open2: $!\n" unless defined $procid; while (<$fh>) { print $WRITEHANDLE $_; } close ($WRITEHANDLE) or die "Error in child: $!\n"; return $READHANDLE; # put in END{}? # waitpid $pid,0; } my $fh = new FileHandle('mailarc-1.txt.gz'); my $dfh = decompress_filehandle($fh); while(<$dfh>) { print $_; } close ($dfh) or die "Error in child: $!\n";
This works fine on Linux, but hangs on the open2 line with Windows XP, ActiveState perl 5.8.0. I can see gzip is running in task manager. I suspect it's some sort of buffering problem. Can anyone help? As a second attempt, I tried using IPC::Run:
use IPC::Run qw( run ); use FileHandle; sub decompress_filehandle { my $fh = shift; my $out = new FileHandle; #run ['gzip','-cd'], $fh, '>pipe', $out; run ['c:\progra~1\cygwin\bin\gzip.exe','-cd'], $fh, '>pipe', $out; return $out; } my $fh = new FileHandle('mailarc-1.txt.gz'); my $dfh = decompress_filehandle($fh); print $_ while <$dfh>;
Unfortunately this hangs on both Linux and WinXP. :( Any suggestions would be appreciated.

In reply to Help!: Open2 Hangs on Windows by coppit

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.