Forum Moderators: coopster & phranque

Message Too Old, No Replies

IIS6 gives CGI application misbehaved

perl scripts that ran OK with IIS5 faile with IIS6

         

Howard

11:31 am on Sep 12, 2007 (gmt 0)

10+ Year Member



The answer to the following

I was tearing my hair out trying to discover why my Perl CGI scripts that have been running for years were now failing having moved to Server 2003 with IIS6.
Permission problems were fairly quickly solved.
That just left the "The specified CGI application misbehaved by not returning a complete set of HTTP headers." error message in the browser, but not for all scripts.

Nowhere could I find a conclusive answer.

My scripts now all work with 3 simple lines, so I thought I should let the rest of you know.

It looks like IIS6 now sends CGI STDERR output to the browser.
Error and warning messages can therefore confuse the browser.
The STDERR stream is also not buffered, and thus if something gets sent to the STDERR stream before the normal document header is produced, the browser will get very confused.

I had
use CGI::Carp qw(fatalsToBrowser carpout cluck croak);
Which I thought wass the problem, but removing that made no difference.
Curtesy of a hidden away text on the CSPAN website, I have now added
BEGIN
{
open(_STDERR,'>&STDERR'); close STDERR;
}

This ensures that the STDERR stream is closed, so no error output is sent to your browser to mess it up.

You could change this to log to a file instead.
There is also CGI::LogCarp which gives a lot of useful timestamped control over output.

perl_diver

1:41 am on Sep 13, 2007 (gmt 0)

10+ Year Member



If you add "warningsToBrowser" to the CGI::Carp import list and use warnings(1) in the perl code you may get the same results instead of redirecting STDERR. See the CGI::Carp documentation for "warningsToBrowser" usage.