Akash Khandelwal
Akash Khandelwal

Reputation: 67

redirect STDERR of eval to /dev/null in perl

eval {require $testRequirePath};

While running the above, if there is syntax error in $testRequirePath file, then it prints it to the STDOUT. I want to redirect it to /dev/null. How can i do it?

Upvotes: 3

Views: 1248

Answers (1)

ysth
ysth

Reputation: 98498

What you are seeing is a warning, not an error; errors will be captured by the eval and placed in $@. To suppress warnings also, you can just do:

eval { local $SIG{__WARN__} = sub {}; require $testRequirePath }

Upvotes: 1

Related Questions