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

I'd appreciate advice on following cgi .... as far as I can tell I've included all possible debug options but the only info I can find is that its a '500 Internal Server Error'
#!c:/perl/bin/perl.exe -wT # ensure all fatals go to browser during debugging and set-up # comment this BEGIN block out on production code for security BEGIN { $|=1; print "Content-type: text/html\n\n"; use CGI::Carp('fatalsToBrowser'); } # all the rest of the code goes here use diagnostics; use strict; my $buffer; read (STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); print "Content-type: text/plain\n\n"; print $buffer;

Replies are listed 'Best First'.
Re: 500 Internal Server Error defies debugging
by ajt (Prior) on Sep 11, 2002 at 11:03 UTC

    Anon,

    What happens when you run the script from the command line?

    The shebang line is for windows, which web server are you running? IIS, Apache or another? IIS needs messing with to get taint working (Taint with Perl on NT/IIS), and doesn't have very useful script/error logging.

    Assuming you have good error logs, and you can read them, what do they say?

    Why are messing with $ENV, CGI.pm is normally the best way to go for parsing CGI input and generating basic HTTP/HTML output. It has been standard with perl for quite a while, it's well regarded, and well tested. See the famous use CGI or die;.


    --
    ajt
Re: 500 Internal Server Error defies debugging
by rdfield (Priest) on Sep 11, 2002 at 10:59 UTC
    Have you check error.log? There's usually some good info in there regarding script failures. And you might want to 'use cgi'...save doing all that reading and parsing of the request yourself. There's plenty of info in and around the Monestary regarding CGI...have a look in the Tutorials section to get started.

    rdfield

Re: 500 Internal Server Error defies debugging
by LTjake (Prior) on Sep 11, 2002 at 11:25 UTC
    Hello AM,

    While I cannot give you an exact answer, I have noticed that you're printing two content types.

    Perhaps the Content-type in the BEGIN block should be removed.

    As a point of reference, I would check out Ovid's CGI Course. See lesson two for why you shoud use CGI;
Re: 500 Internal Server Error defies debugging
by blssu (Pilgrim) on Sep 11, 2002 at 13:16 UTC

    Sometimes a 500 error means the web server can't run the script at all -- perl may not even be starting. Look at the last few lines of the error log. Check your web server configuration. Try running a trivial "hello, world" Perl script.

Re: 500 Internal Server Error defies debugging
by Anonymous Monk on Sep 11, 2002 at 15:41 UTC
    Having done more VB than Perl, and having created several ISAPI dlls that work just fine most of the time, I know that the 500 error is sometimes just IIS puking of its own accord and not a problem with your code, for what its worth.
Re: 500 Internal Server Error defies debugging
by busunsl (Vicar) on Sep 11, 2002 at 13:31 UTC
    Have a look at this.
Re: 500 Internal Server Error defies debugging
by krujos (Curate) on Sep 11, 2002 at 13:36 UTC
    Make sure your file permissions are set correctly.