[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 692
  • Last Modified:

Not able to execute cgi scripts

hello all
I have apache running on Windows and to make cgi files work , I have modified the httpd file and changed the AddHandler to

AddHandler cgi-script .cgi .pl
 ScriptInterpreterSource Registry

still when I execute the cgi script through browser , what I get is 500 server error stating that Premature end of script headers
but I execute perl scripts without any problems
whats wrong with cgi scripts
0
ronan_40060
Asked:
ronan_40060
  • 6
  • 4
  • 3
  • +4
3 Solutions
 
j_dyerCommented:
Could be a number of things wrong really but...
The first thing which springs to mind is that you may not be sending the correct (any?) http headers back.
Normally, the first thing your script should print is:
Content-type: text/html


Note - there needs to be a blank line between the last header, and the first thing you want sent to the web browser ie,
in Perl, you'd do something like this:

print "Content-type: text/html\n\n";    // Note double '\n' here
print "<HTML>\n<HEAD>\n";             // etc.

If this isn't the answer, could you post one of the scripts you're having a problem with?
0
 
healthstatusCommented:
Just for fun, change the extension to .pl and see if it runs.  Also, look in the Apache error log file, really good information lives here when Perl programs blow up, it is your friend, learn to read it.  Are you using ActiveState Perl?
0
 
ronan_40060Author Commented:
hello j_dyer and healthstatus thanks for the replies
I execute all perl scripts without any problems but its the only cgi files that Im having problems
yes Im using activeperl
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
healthstatusCommented:
OK, so did you try and change the extension to .pl and execute it along the lines of http://localhost/cgi-bin/myscript.pl
0
 
ronan_40060Author Commented:
it works when i convert it to .pl
and add use strict; and use warnings;
0
 
healthstatusCommented:
OK, a couple of options, change all your CGI files to .pl or make sure you have mappings in all the right places for .cgi files to be executed by Perl, File types(under tools/folder options in explorer) is probably what you need to setup.
0
 
ahoffmannCommented:
you need to add .cgi extension for calling perl to the registry
That's the way M$ works ...
0
 
GlauronCommented:
Also - depends what ur using to create the files -

Try adding a couple BLANK lines at the END of the CGI script.... I had strange happenings in some of my scripts, but that fixed it!!

(make sure they are linux blank lines (line feed?) - not windows (carriage return?))
0
 
ahoffmannCommented:
> Try adding a couple BLANK lines at the END of the CGI script....
are you joking (about M$) ??
0
 
mishagaleCommented:
If you get a premature end of script headers, it almost certainly means that the script didn't output a "Content-type:" header. This is usually because something caused an error in the script before the "print 'Content-type:...'" line, and the web server took the error message and thought it was the scripts output. The fact that you even got a 500 error, and not simply the source of the script seems to indicate that Apache is indeed handling it as perl and executing it. If the script works fine from command line but not from the server, remember that the cmd-line environment is subtly different from the server - there are different paths and enviroment variables.

I would also try adding a "use CGI::Carp qw(fatalsToBrowser);" pragma to your script, that way you will get a more friendly error message than "Premature end of script headers"

P.S. My experience of these matters is entirely uncomtaminated by the heresy that is MS Web Servers, so I may very well be mistaken here.
0
 
rmaz410Commented:
I had a similar proble, but it was with RedHat 9.0.  In your script on the "shebang line", add a " -w" to the end of the call to perl
So, for example, change
#!/usr/bin/perl
to
#!/usr/bin/perl -w

See what happens
0
 
mishagaleCommented:
rmaz: He is running on windows, so the shebang line will be ignored anyway.
0
 
GlauronCommented:
Heheh - no I wasn't joking about blank lines believe it or not!!! weird huh.
Mishagale is right with his statement ...
(Not printing headers for some reason etc.)

Have a look at when/where/how your headers are printed.
0
 
ahoffmannCommented:
> ..  it almost certainly means that the script didn't output a  "Content-type:" header.
or, if not "almost certainly", the script returned other status than 0 ;-)
someone checked if the script is in proper M$ format (each line ending with \r\n)?
0
 
healthstatusCommented:
His script runs when he renames it to .pl, this is not a Perl problem, it is getting the OS to execute .cgi files.  Shebang lines are ignored for looking where Perl is run from but the flags -w -t etc will be executed.
0
 
ronan_40060Author Commented:
yes I can execute all the scripts when I change the extension from .cgi to .pl
but I didnt not understand it well how to get Windows to execute .cgi files
regards
0
 
healthstatusCommented:
Right click your start button, click explore, click tools from the menu, then folder options, and the tab file types  make sure there is an entry for .cgi that matches the entry for .pl, OR JUST CHANGE THE NAMES OF YOUR SCRIPTS TO .PL (that is by far the easiest without any downside except changing your links)
0
 
ronan_40060Author Commented:
I see perl entry but theres no entry for .cgi
should I create .cgi entry
0
 
healthstatusCommented:
yes!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 4
  • 3
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now