Thanks for the explanation. What if I fork, and have the child process feed data to the parent? That way the parent can read from the pipe when it needs to, and the child can fill it independently of the parent. Here's the modified code:
use FileHandle; sub pipe_from_fork ($) { my $parent = shift; pipe $parent, my $child or die; my $pid = fork(); die "fork() failed: $!" unless defined $pid; if ($pid) { close $child; } else { close $parent; open(STDOUT, ">&=" . fileno($child)) or die; } $pid; } sub decompress_filehandle { my $fh = shift; my $dfh = new FileHandle; # Must use pipe_from_fork because $dfh->open('-|') not yet implement +ed on # Windows. See perlfork for details unless (pipe_from_fork($dfh)) { # In child close $dfh; open(FRONT_OF_PIPE, '| c:\progra~1\cygwin\bin\gzip.exe -cd') or return (undef,"Can't execute \"$filter_command\" on file hand +le: $!"); print FRONT_OF_PIPE <$fh>; $fh->close() or return (undef,"Can't execute \"$filter_command\" on file hand +le: $!"); close FRONT_OF_PIPE; exit; } # In parent close $fh; return $dfh; } my $fh = new FileHandle('mailarc-1.txt.gz'); my $dfh = decompress_filehandle($fh); print $_ while <$dfh>;
As before, this works on Unix but not Windows. It seems to hang trying to close the pipe to gzip -cd. I would have thought that this would be a common thing to do, even on Windows...

In reply to Re: Re: Help!: Open2 Hangs on Windows (doomed) by coppit
in thread 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.