通常我使用Python但我在Perl中有一个项目。那么:将snmpwalk的结果指向字符串的过程是什么?我想搜索字符串以查看它是否包含更小的字符串。
这是我到目前为止所做的:
foreach (@list){
chomp($_);
system("snmpwalk -v 2c -c community-string $_ oid-hidden");
if (index($string, $substring) != -1) {
print "'$string' contains '$substring'\n";
}
}
答案 0 :(得分:2)
system
函数不会返回函数输出,使用qx//
或反引号,所以你的snmpwalk调用行将如下所示:
my $output = qx/snmpwalk -v 2c -c community-string $_ oid-hidden/;
然后你使用输出变量做你需要的东西,更多信息我会推荐你http://perldoc.perl.org/perlop.html#Quote-Like-Operators
然而,更一般地说,我会遵循@ ThisSuitIsBlackNot评论中的建议......