Improve company productivity with a Business Account.Sign Up

x
?
Solved

Not able to execute cgi scripts

Posted on 2004-04-06
19
Medium Priority
?
694 Views
Last Modified: 2013-12-25
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
Comment
Question by:ronan_40060
  • 6
  • 4
  • 3
  • +4
19 Comments
 
LVL 2

Expert Comment

by:j_dyer
ID: 10765399
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
 
LVL 2

Expert Comment

by:healthstatus
ID: 10765591
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
 
LVL 9

Author Comment

by:ronan_40060
ID: 10765665
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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 2

Expert Comment

by:healthstatus
ID: 10765714
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
 
LVL 9

Author Comment

by:ronan_40060
ID: 10765797
it works when i convert it to .pl
and add use strict; and use warnings;
0
 
LVL 2

Accepted Solution

by:
healthstatus earned 1200 total points
ID: 10765962
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
 
LVL 51

Expert Comment

by:ahoffmann
ID: 10777618
you need to add .cgi extension for calling perl to the registry
That's the way M$ works ...
0
 
LVL 1

Expert Comment

by:Glauron
ID: 10830042
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
 
LVL 51

Expert Comment

by:ahoffmann
ID: 10830314
> Try adding a couple BLANK lines at the END of the CGI script....
are you joking (about M$) ??
0
 
LVL 2

Assisted Solution

by:mishagale
mishagale earned 400 total points
ID: 10836026
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
 
LVL 1

Expert Comment

by:rmaz410
ID: 10837009
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
 
LVL 2

Expert Comment

by:mishagale
ID: 10837364
rmaz: He is running on windows, so the shebang line will be ignored anyway.
0
 
LVL 1

Expert Comment

by:Glauron
ID: 10839167
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
 
LVL 51

Assisted Solution

by:ahoffmann
ahoffmann earned 400 total points
ID: 10839835
> ..  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
 
LVL 2

Expert Comment

by:healthstatus
ID: 10840910
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
 
LVL 9

Author Comment

by:ronan_40060
ID: 10842028
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
 
LVL 2

Expert Comment

by:healthstatus
ID: 10842113
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
 
LVL 9

Author Comment

by:ronan_40060
ID: 10842204
I see perl entry but theres no entry for .cgi
should I create .cgi entry
0
 
LVL 2

Expert Comment

by:healthstatus
ID: 10842246
yes!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

595 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question