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

I have a script that sends an e-mail using Net::SMTP. It works fine when run from the command line as root. However, when run as a cgi-bin as the webserver's user, apache, it fails with $! = Permission Denied. I want to set Debug to 1 and capture the debug output. How do I do that in a CGI script?
  • Comment on Capture Net:::SMTP debug output in a CGI script

Replies are listed 'Best First'.
Re: Capture Net:::SMTP debug output in a CGI script
by gmargo (Hermit) on Oct 28, 2009 at 15:41 UTC

    According to the man page, Net::SMTP debugging is sent to STDERR (see the parent class Net::Cmd documentation.) Since you're using Apache, the STDERR stream will go to the normal Apache error log file, perhaps /var/log/apache2/error.log.

    If the above is not what you want, and you truly want to "capture" the output, for further processing by your script, you'll need to redirect STDERR to a file. The open function documentation shows how to save and restore STDERR.

Re: Capture Net:::SMTP debug output in a CGI script
by Khen1950fx (Canon) on Oct 28, 2009 at 15:45 UTC
    Try CGI::Debug. Put use CGI::Debug on the second row, and you're good to go.