2012-12-10 63 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