2012-12-10 62 views
0

我的脚本运行这个命令,它总是给出三个警告。有没有办法将这些过滤掉?过滤掉系统调用的警告

my $output = `cleartool mktag -view -tag test -reg win_region -host view_server1 -gpath \\\\view_server\\view_directory1\\test.vws/viewstore/view_directory1/test.vws\` 

的警告是这个样子:

cleartool: warning: The global pathname "blabla" in the non-default region will not be validated 
cleartool: warning: Unable to access "blabla": No such file or directory 
cleartool: warning: Storage pathname "blabla" may not reside on host 

回答

3

假设外部工具写入STDERR你可以告诉shell重定向别处。通常的做法是将2> /dev/null附加到您通过反引号运行的命令。

如果你需要其他的警告和错误,然后在一个临时文件(见File::Temp对于如何安全地生成的临时文件)通过重定向2> $temp_file_name捕捉STDERR,阅读用Perl(即文件中看到File::SlurpIO::All,便于使用的一个用于读取像my @captured_stderr = read_file($temporary_file_name);这样的文件的衬垫),用Perl的grep函数丢弃不需要的行,并将其余行返回到STDERRprint STDERR @captured_stderr)。

+0

我仍然希望看到其他警告或错误。这会消除一切?谢谢你的回答 – user1758367

+0

我已经在我的答案中添加了相关建议。 –

+0

非常感谢!我可以在2分钟内标记为答案。 – user1758367