?
Solved

Not able to execute cgi scripts

Posted on 2004-04-06
19
Medium Priority
?
688 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Suggested Courses

770 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