Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Suppressing error outputs 1

Status
Not open for further replies.

teser

Technical User
Mar 6, 2001
194
US


I am running a script on my Solaris 7 OS and want to eliminate error outputs the same way Unix uses the 2> /dev/nul.

HOw can I suppress error outputs in Perl??

 
The quickest way to do this is to redirect stderr to /dev/null near the top of the script. This will direct any runtime stderr output from die() or warn() to /dev/null.
Code:
open STDERR, "/dev/null" or die "Cannot redirect stderr: $!";

If you are stuck on never receiving a single error message from your script then you can wrap the above statement in a BEGIN block.
Code:
BEGIN {
    open STDERR, "/dev/null" or die "Cannot redirect stderr: $!";
}
This will swallow up all runtime errors and any compile time errors that are generated after the BEGIN phase (ie use()ing a module that doesn't exist will still generate and error to the terminal). This second option isn't a good way to go because if there are any errors in the script it will just quit silently.

jaa
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top