Suppressing method error messages

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);

but if ticket number ‘$i’ doesn’t exist, I get an ugly message from the
Ticket->Load method:

[crit]: RT::Ticket=HASH(0x8c89988) tried to load a bogus ticket:

when all I want to do is continue without printing anything. (In general,
redirecting STDERR to /dev/null is not feasible, since I may want to write
my own messages there and have them seen).

Thanks.

Mike

Mike Friedman System and Network Security
mikef@ack.Berkeley.EDU 2484 Shattuck Avenue
1-510-642-1410 University of California at Berkeley
http://ack.Berkeley.EDU/~mikef http://security.berkeley.edu

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?

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@ack.Berkeley.EDU 2484 Shattuck Avenue
1-510-642-1410 University of California at Berkeley
http://ack.Berkeley.EDU/~mikef http://security.berkeley.edu

Mike Friedman 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
Same problem in RTx::Shredder that’s why I ship it with patch. Didn’t
envestigate other variants.