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>;
In reply to Help!: Open2 Hangs on Windows by coppit
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |