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

I am writing a CGI app that will execute a program and mail a user the output. The program runs for a long time so I close and reopen STDOUT, STDERR, and STDIN to /dev/null to send apache an EOF. This does not seem to jive well with Net::SMTP. When I comment out the lines:
close STDIN; close STDOUT; close STDERR; open STDIN, "</dev/null"; open STDOUT, ">/dev/null"; open STDERR, ">/dev/null";
Net::SMTP sends email without problem. No warning or error messages appear in the apache error log, nor when I execute the script from shell.

When I uncomment those lines and run the command in a shell, it still works, mail is sent as usual. However, now when run in a browser mail will not get sent. I do not run the smtp server or I would look in the logs whether it connects or not. This makes me think it might be an apache issue and not perl.

I am using the standard redhat apache install with a standard redhat perl.

Tell me if it would be useful to have the full code. It is quite long so I will post it in a separate node.

Here are my version numbers:
Server version: Apache/2.0.48
Server built: Feb 26 2004 23:02:17

This is perl, v5.8.0 built for i386-linux-thread-multi
I am running perl with -T if that makes a difference.

$Net::SMTP::VERSION = 2.24

Thanks in advance.

Update: It seems that the issue is with closing and reopening both STDOUT and STDERR. Closing either individually allows Net::SMTP to function. Could this be a LANG issue with utf8?

Replies are listed 'Best First'.
Re: Net::SMTP and closing STDOUT/STDERR/STDIN
by BUU (Prior) on Apr 15, 2004 at 04:42 UTC
    I suggest you create a small, 10-20 line test case that demonstrates the problem.
Re: Net::SMTP and closing STDOUT/STDERR/STDIN
by jdtoronto (Prior) on Apr 14, 2004 at 19:16 UTC
    I think I see what you are trying to do - free up the parent process. But why are you outputting STDERR to nowhere?

    Maybe should should either read 'Starting a Long Running External Program' on p379 of "Practical mod_perl" (from O'Reilly) or read the mode_perl documentation here to see what does work.

    jdtoronto