coppit has asked for the wisdom of the Perl Monks concerning the following question:
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::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";
Unfortunately this hangs on both Linux and WinXP. :( Any suggestions would be appreciated.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>;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Help!: Open2 Hangs on Windows (doomed)
by tye (Sage) on Sep 04, 2003 at 19:47 UTC | |
by coppit (Beadle) on Sep 04, 2003 at 21:11 UTC | |
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 | |
|
Re: Help!: Open2 Hangs on Windows
by runrig (Abbot) on Sep 04, 2003 at 21:59 UTC | |
|
Re: Help!: Open2 Hangs on Windows
by graff (Chancellor) on Sep 05, 2003 at 04:09 UTC |