tags:

views:

713

answers:

4

I am trying to run some Perl CGI scripts under IIS. I get the following message :


CGI Error
The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are:

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
    LC_ALL = (unset),
    LANG = (unset)
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").

I found out that the problem occurs only when I "use" an internal library of ours but it's really a big one (using many other stuff) so I would prefer to know where to look. When I run the same script from the command line, the script runs just fine. I tried to set "LANG" to "C", then "LC_ALL" to "C" but it had no effect.

Any pointers welcome!

A: 

It seems your Perl application is sending it's errors to the browser, and an error happens before a header is sent.

If you are using the CGI module, the first may be caused by use CGI::CARP qw(fatalsToBrowser).

In this case fatalsToBrowser does more harm than it is of use, so I'd advice you to turn it off for now.

Leon Timmermans
Actually, "CGI::Carp arranges to send a minimal HTTP header to the browser so that even errors that occur in the early compile phase will be seen." (from CGI::Carp's docs).I suspect Perl itself is responsible for the warnings?
David Precious
I'm making an educated guess here. If I remember correctly, IIS wants/wanted the first line of a HTTP response header too ("HTTP/1.1 200 OK"), unlike apache and most other webservers. It may be that CGI::Carp doesn't do that.
Leon Timmermans
A: 

The perldoc for locale might help you. It even features a troubleshooting section.

innaM
A: 

You can suppress this error by setting PERL_BADLANG=0, though that, like LC_ALL, needs to be set before your Perl script runs.

ysth
+2  A: 

The LANG and LC_ALL environment variables are set for your shell, but they aren't set for IIS. I'm not an IIS person, but the docs say that IIS is a service and you have to set those ahead of time then reboot.

Alternatively, you can set these variables as soon your script starts to compile (and before you load your large library that is causing the problems:

BEGIN {
 $ENV{LC_ALL} = ...;
 $ENV{LANG} = ...;
 }

Get the values that you should use by looking at the ones you have in your shell.

Good luck,

brian d foy