Perl:隐藏系统输出

在Linux上使用Perl 5.8.8,需要隐藏perl'system'命令的输出。 我的代码中的命令是:

system("wget", "$url", "-Omy_folder/$date-$target.html", "--user-agent=$useragent"); 

我已经尝试在系统命令的不同位置使用> /dev/null 2>&1 ,如下所示:

 system("wget", "$url", "-Omy_folder/$date-$target.html", "--user-agent=$useragent","> /dev/null 2>&1"); 

任何人都可以帮助我redirect到/dev/null应该在哪里?

当你用多于一个arg调用system()时,你告诉perl直接把它传递给exec *()调用之一,所以它不会被shell调用。 shell是理解文件redirect的东西。 尝试这个:

 system("wget $url -Omy_folder/$date-$target.html --user-agent=$useragent >/dev/null 2>&1"); 

请注意,这在技术上不如直接将它传递给exec。

对于引用使用String :: ShellQuote,或者只是自己实现逻辑:

 sub sq { my $str = shift; if (!$str) { $str = "''"; } else { $str =~ s|'|'\\''|g; $str = "'$str'"; $str =~ s|^''||; $str =~ s|''$||; } return($str); } $useragent = sq($useragent); system("wget $url -Omy_folder/$date-$target.html --user-agent=$useragent >/dev/null 2>&1"); 

此外,为了让这个更多一点的系统pipe理员和一个less一点的程序员,你有没有考虑使用-q选项wget而不是跳过shell /文件redirect的箍?