Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

TagLib messages

by Rodster001 (Pilgrim)
on Jun 24, 2015 at 15:25 UTC ( #1131831=perlquestion: print w/replies, xml ) Need Help??

Rodster001 has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

When parsing an mp3 file using Audio::TagLib, quite often I see these messages:
TagLib: MPEG::Header::parse() -- Invalid sample rate. TagLib: MPEG::Header::parse() -- Invalid sample rate. TagLib: MPEG::Header::parse() -- Invalid sample rate. TagLib: MPEG::Header::parse() -- Invalid sample rate. TagLib: MPEG::Header::parse() -- Invalid sample rate. TagLib: MPEG::Header::parse() -- Invalid sample rate. TagLib: MPEG::Header::parse() -- Invalid sample rate. TagLib: MPEG::Header::parse() -- Invalid sample rate. TagLib: MPEG::Header::parse() -- Invalid sample rate. TagLib: MPEG::Header::parse() -- Invalid sample rate.
Sometimes a few lines, sometimes a lot. I understand the nature of the problem and it's safe to ignore. So is there anyway to silence these messages (and only these messages) without redirecting all output to /dev/null (or something like that)?

Thanks!

Replies are listed 'Best First'.
Re: TagLib messages
by stevieb (Canon) on Jun 24, 2015 at 17:12 UTC

    One way is to put the specific code that is generating the warning into a block that redirects STDOUT. You'll want to ensure you limit the scope, because if any other warnings are generated, you won't see them.

    #!/usr/bin/perl use warnings; use strict; sub warning { print "ERROR!!!\n"; } my $out; open my $stdout, '>', \$out or die $!; { local *STDOUT = $stdout; warning(); }

    -stevieb

      Perhaps a patch to the maintainer providing a method to categorize the warnings so you can silence the warnings of only the type you want?

      Jason L. Froebe

      Tech Blog

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1131831]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (1)
As of 2021-10-20 22:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (82 votes). Check out past polls.

    Notices?