=item do_pipe_command Mostly-simply wrapper around open for piping from a command. Since we generally want to capture stderr, too, we redirect stderr to stdout in the command, so we get it all in a single filehandle. =cut sub do_pipe_command { print 'Running: ', join(' ', @_[1..$#_]), $/; my $pid = open ($_[0], '-|'); return $pid if $pid; # child - pipe the stderr to the stdout before exec'ing. open STDERR, '>&', \*STDOUT; my @cmd = @_[1..$#_]; if ($^O =~ /MSWin/i) { @cmd = (qw(cmd.exe /c), join(' ',@cmd)); } exec @cmd; } =item extract_tarball Tries to untar the tarball. Returns the directory name thusly created. =cut sub extract_tarball { my $tarball = shift; my $cmd = ''; if ($tarball =~ /\.tar\.gz$/) { $cmd = "gunzip -c $tarball | "; } elsif ($tarball =~ /\.tar\.Z$/) { $cmd = "zcat $tarball | "; } elsif ($tarball =~ /\.tar$/) { $cmd = "cat $tarball | "; } else { die "Can't figure out how to untar $tarball"; } $cmd .= 'tar -xvf -'; print "Running $cmd\n"; my $subdir; do_pipe_command my $tar, $cmd or die "Failed to run $cmd: $!"; while (my $l = <$tar>) { print $l; next if $subdir; $subdir = $1 if $l =~ m:^(.*?)[/\\]:; } $subdir; } #### Running gunzip -c Cache-Repository-0.01.tar.gz | tar -xvf - Running: gunzip -c Cache-Repository-0.01.tar.gz | tar -xvf - '-' is not recognized as an internal or external command, operable program or batch file. Use of uninitialized value in string eq at e:/perl5.8.0/lib/File/Spec/Unix.pm line 77. #### sub do_pipe_command { print 'Running: ', join(' ', @_[1..$#_]), $/; my @cmd = @_[1..$#_]; my $wtr; require IPC::Open3; my $pid = IPC::Open3::open3($wtr, $_[0], undef, @cmd); }