Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Running Perl Scripts

by Sajoe (Initiate)
on Nov 06, 2003 at 03:10 UTC ( [id://304934]=perlquestion: print w/replies, xml ) Need Help??

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

Hello,

Im a beginner to programming in Perl. Ive already installed IIS and ActivePerl software. IIS works just fine as ive tested it with ASP scripts. However, when I run a basic perl script from localhost in IIS 5.1 (ie. http://localhost/hello.pl-where my virtual scripts directory is c:/inetpub/scripts) but am stuck with the following error:

CGI Error The specified CGI application misbehaved by not returning a complete s +et of HTTP headers. The headers it did return are: Too late for "-T" option at C:\Inetpub\Scripts\hello.pl line 1.

What does this mean and how do i fix it? Below is the code that ive created in hello.pl:

#!C:\Perl\bin\perl.exe -wT use strict; use cGI ':standard'; print "Content-type: text/html"; print "<html>"; print "<head><title>wow</title></head>"; print "<body>"; print "IIS Perl Interpreter works jus fine"; print "</body>"; print "</html>";
Thank you in advance I hope to hear from you soon! Joe

Edit by thelenm: formatting

Replies are listed 'Best First'.
Re: Running Perl Scripts
by Roger (Parson) on Nov 06, 2003 at 03:17 UTC
    As for the "too late for -T" part - you did not invoke the perl script with 'perl -T script.pl'.

    The #! line in your perl script has the -T option, but the perl interpreter was not invoked with -T in its argument list. By the time Perl discovers a -T in the script, it's too late to properly taint everything from the environment. Therefore Perl gives up with the error message.

    The quick fix: just drop the -T in your perl script. You don't really need it here.

    Also the line
    print "Content-type: text/html";
    needs to have two returns. Change it to
    print "Content-type: text/html\n\n";
    The two returns will insert a blank line after the Content-type, and this is required by the server. Otherwise you will get server errors.

    You probably want to use HEREDOC too otherwise you will have to keep typing 'print' and quotes ... :)

    I have created a demo program for you. It uses the CGI module to format a proper Content-type header, and then HEREDOC for the content of the HTML.

    #!C:\Perl\bin\perl.exe -w use strict; use CGI; my $cgi = new CGI; print $cgi->header(), <<HTML <html> <head><title>wow</title></head> <body> IIS Perl Interpreter works jus fine </body> </html> HTML ;
Re: Running Perl Scripts
by sunadmn (Curate) on Nov 06, 2003 at 03:35 UTC
    It seems like my fellow monks have given you good advice, but I would also like to add that maybe a good CGI driven course would help you out and the best I have found on the net comes from one of our fellows monks please take a look at Ovid's courese. Also on a side note for some good books on the subject and many others goto this site and sign up it's worht the time I promise Safari. I hope this will help you in your quest for enlightenment.

    -Sunadmn
Re: Running Perl Scripts
by inman (Curate) on Nov 06, 2003 at 08:54 UTC
    You can resolve the 'Too late for Taint checking' issue fairly easily and still have taint checking. This node describes how to set it up.

    inman

Re: Running Perl Scripts
by tcf22 (Priest) on Nov 06, 2003 at 03:30 UTC
    A blank line("\n\n") is required to signal the end of your headers.

    print "Content-type:text/html\n\n"; should fix the issue in this script. When you get into more complicated CGIs dealing with cookies, expirations and such, you only put the blank line at the end of all headers.
    print "header1:value1\n"; print "header2:value2\n"; print "header3:value3\n\n";
    You may also want to consider using CGI methods to output you headers and html. I personally prefer HTML::Template, but either will work.

    - Tom

      Ummm, I think his immediate problem isn't the misformatted content type header, but rather with the -T option in the #! line of the perl script.

      When the -T option is removed, then the content type header problem will show up.

Re: Running Perl Scripts
by ysth (Canon) on Nov 06, 2003 at 03:47 UTC
    The responses so far should have helped you out. I'd like to add that the 'Too late for "-T"' error came from perl and (as with all perl errors) you can look up documentation about it by running "perldoc perldiag" and searching for 'Too late for'.

    If you are downvoting this for other than lack of interest, thanks for sending me a message or reply to let me know why so I can do better (or just stay quiet) next time.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://304934]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-25 23:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found