Skip to content

@pmorch /workaround.pl
Last active

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Workaround for SNMP::Session->new(DestHost=>"bogus") printing to STDERR
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
Something went wrong with that request. Please try again.