in reply to Re: Help!: Open2 Hangs on Windows (doomed)
in thread Help!: Open2 Hangs on Windows
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...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>;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Help!: Open2 Hangs on Windows (doomed)
by BrowserUk (Patriarch) on Sep 04, 2003 at 23:25 UTC | |
by graff (Chancellor) on Sep 05, 2003 at 03:48 UTC | |
by tye (Sage) on Sep 05, 2003 at 05:11 UTC | |
by coppit (Beadle) on Sep 11, 2003 at 21:25 UTC |