Solved

Not able to execute cgi scripts

Posted on 2004-04-06
19
657 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
 
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 300 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 2

Assisted Solution

by:mishagale
mishagale earned 100 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 100 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
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 the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

708 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now