如何捕獲由Perl調用的wget中的STDOUT返回值,並將其放入一個變量中?如何從Perl打開管道捕獲STDOUT?
my @urls = ('url1', 'url2', 'url3');
open(GET, "| xargs -n1 -P 3 wget -qO- ") || die "get failed: $!\n";
print GET "@urls";
如何捕獲由Perl調用的wget中的STDOUT返回值,並將其放入一個變量中?如何從Perl打開管道捕獲STDOUT?
my @urls = ('url1', 'url2', 'url3');
open(GET, "| xargs -n1 -P 3 wget -qO- ") || die "get failed: $!\n";
print GET "@urls";
首先,your pipe is an input pipe, and open
doesn't support both input and output pipes。作爲替代方案,使用管道輸出,並打開一個文件句柄每網址:
use strict;
use warnings;
my @urls=qw(url1 url2 url3);
foreach my $url(@urls)
{
open(my $get,"-|","wget $url") or die $!;
print while(<$get>);
close($get);
}
Hooray ...還有更多系列downvoting。 – 2012-11-16 10:30:21