perl脚本中运行含有管道的系统命令时,不能将错误输出重定向到文本
bu110 2012-10-08 04:16:41 我有一段perl脚本如下:
while(1)
{
my @i = ();
my $command = <FH>;
if(not defined ($command))
{
last;
}
chomp($command);
print RESULT "$command\n";
@i = `$command 2>&1`;
print RESULT @i;
}
FH和RESULT 都是文件句柄,
结果文件:
cat /etc/opasswd1
cat: /etc/opasswd1: No such file or directory
cat /etc/opasswd1 | grep -v "^#"
好像命令行中不加管道就能将标准输出打印到文本中,加了管道就不能输出到文本中,但是会打到屏幕上,
请高手帮忙看下,谢谢!