Why does my Perl CGI complain about "Premature end of script headers"?

cgi, perl

Solution

"Premature end of script headers" is not a terribly useful error message on its own. It could be caused by any of a number of things, such as:

- not being executable (permissions problem)

- failing compilation (syntax error, dependency problem, etc.)

- terminating prematurely during regular execution

- producing something other than proper HTTP headers as your script's first output

However, in this case, if we are to take your example script literally (`print "TEST"`), and you output this before your HTTP headers, then you are not producing HTTP headers first, so it's the last one. The web server expects headers, not "TEST."

If that's not the case, we need to see more of the context of your code to know what might have happened. Could be a permissions problem executing `test.pl`, for example.

Problem

I'm sure someone could answer this very quickly, but I'm just new to perl... I'm trying to modify demarc (a simple network monitoring tool) to do a system call to a simple script. The script itself does nothing, I'm just trying to do a 'proof-of-concept' because I keep getting an internal server error. Permissions to the script have been set to 777. When I comment the system() call, everything's fine. So that makes me suspect that it's the system() call where the error's happening. I've also tried exec(), but that didn't work also. The error could not be in the script itself since there's only an echo "test" in it. Have I missed any permissions or is there some other way of making this work? Any advise would be appreciated. ``` sub generate_ticket { my @args = ("$base_path/test.pl"); exec(@args); } ``` This is called somewhere in file like this: ``` } elsif ($FORM{'delete_type'}=~/generate/) { my $message = &generate_ticket($delete_array_ref); #&ack_events($delete_array_ref); $events_deleted = (@$delete_array_ref); &push_message("<FONT COLOR=red><B>Result: $message.</B></FONT>"); } ``` test.pl: ``` #!/usr/bin/perl print "Test"; ``` Error log: [Mon Nov 30 14:58:22 2009] [error] [client 127.0.0.1] Premature end of script headers: demarc, referer: http://localhost/dm/demarc?td=show_events&limit=60&sid=35

Original source