[rt-users] Suppressing method error messages
Mike Friedman
mikef at ack.Berkeley.EDU
Fri Oct 22 14:08:24 EDT 2004
On Fri, 22 Oct 2004 at 21:31 (+0400), Ruslan U. Zakirov wrote:
> Mike Friedman wrote:
>> Is there an easy way, in a perl script, to suppress error messages written
>> by RT methods to STDERR? For example, inside a loop, I have something
>> like this:
>>
>> $TicketNumber = $TicketObj->Load($i);
>> next unless (defined $TicketNumber);
> Why don't you RT::Tickets object instead?
I'm using an RT::Ticket object, $TicketObj is just a loop variable whose
value is such an object. I need the RT::Ticket->Load method in order to
load a specific ticket number(*). (I don't see a Load method in
RT::Tickets, only in RT::Ticket).
(*) Because the purpose of this script is to run through a range of
tickets looking only for those that have status 'deleted'. Which means I
can't use LimitStatus, for example, because it won't return deleted
tickets.
Looking in the source for Ticket_Overlay.pm, I see where it is writing out
error messages. It's those messages I want to suppress. The docs say
that if the specified ticket number doesn't exist, 'undef' is returned,
which is true and that's all I need. I don't want an error message to
appear; I'll just terminate my loop silently in that case.
As it happens, I have found a workaraound, using perl facilities. I dup
the STDERR filehandle, save its destination, temporarily open STDERR as
/dev/null and then reset the original destination for STDERR when I am no
longer using Ticket->Load. But this approach could get ugly in other
scripts, where I might be writing my own error messages even as I'm also
using the Ticket->Load method.
Mike
------------------------------------------------------------------------------
Mike Friedman System and Network Security
mikef at ack.Berkeley.EDU 2484 Shattuck Avenue
1-510-642-1410 University of California at Berkeley
http://ack.Berkeley.EDU/~mikef http://security.berkeley.edu
------------------------------------------------------------------------------
More information about the rt-users
mailing list