Last active
September 27, 2015 04:18
-
-
Save pmorch/1210984 to your computer and use it in GitHub Desktop.
Workaround for SNMP::Session->new(DestHost=>"bogus") printing to STDERR
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my $sess; | |
my ($tempSTDERR, $STDERRfilename) = File::Temp::tempfile(); | |
open SAVE_STDERR, '>&STDERR'; | |
open STDERR, '>&' . fileno($tempSTDERR); | |
# If SNMP::Session->new() is going to die for whatever reason, make sure we | |
# restore STDERR first! | |
eval { | |
$sess = SNMP::Session->new( | |
'Community' => 'public', | |
'DestHost' => 'bogus', | |
'Version' => '2c', | |
); | |
}; | |
my $err = $@; | |
# Don't juse use | |
# open STDERR, '>&SAVE_STDERR'; | |
# because it gives this warning: | |
# Name "main::SAVE_STDERR" used only once: possible typo | |
# refering to the line opening SAVE_STDERR above | |
open STDERR, '>&' . fileno(SAVE_STDERR); | |
close $tempSTDERR; | |
die $err if $err; | |
my $stderrOutputDuringSessionNew = `cat $STDERRfilename`; | |
unlink $STDERRfilename; | |
chomp $stderrOutputDuringSessionNew; | |
if ($stderrOutputDuringSessionNew ne '') { | |
warn sprintf "STDERR output from SNMP::Session->new(): '%s'", | |
$stderrOutputDuringSessionNew; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The bug was given an ID: 3408007 URL: https://sourceforge.net/tracker/?func=detail&aid=3408007&group_id=12694&atid=112694