Why is my Perl CGI complaining about "Premature end of script headers"?

I'm sure someone can answer this very quickly, but I'm just not familiar with perl ...

I am trying to modify demarc (a simple network monitoring tool) to make 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. The permissions for the script are set to 777. When I comment on the system () call, everything is fine. Therefore, I suspect this is a system () call where an error occurs. I also tried exec (), but that didn't work either. The error cannot be in the script itself, since it has only an "echo test".

Am I missing any permissions or is there another way to make this work? Any recommendations would be appreciated.

sub generate_ticket {
   my @args = ("$base_path/test.pl");
   exec(@args);
}

This is called somewhere in the file as follows:

} 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

+5
source share
10 answers

"Premature end of script headers" is not a very useful error message. This can be caused by any of several things, for example:

  • not executable (permission issue)
  • failed compilation (syntax error, dependency problem, etc.)
  • termination prematurely during normal execution
  • - , HTTP-, script

, script (print "TEST"), HTTP-, HTTP, . - , "TEST".

, , , . , , test.pl.

+7

, system, exec:

exec - exec, , .

exec.

+2

, , , , -, , .

+2

- . , , , - :

BEGIN {
    print "Content-type: text/plain\n\n";
}

.

+2

. 500 Server Error Perl.

, script ?

+1

Perl CGI, , Apache. Apache , CGI script , , .

CGI printenv script, ,

#!/usr/bin/env perl

use warnings;
use strict;

print "Content-type: text/plain\r\n\r\n";
print "$_ => $ENV{$_}\r\n" for sort keys %ENV;

, - .

+1

, test.pl. system exec ( exec script test.pl).

:

my $message = `$base_path/test.pl`;
0

, .

:

  • - test2.pl, - .
  • script.

    #!/bin/perl 
    use feature 'say';
    use strict;
    use warnings;
    use Data::Dumper;
    use English qw<$OS_ERROR>;
    
    my $rc = system( "$base_path/test2.pl" );
    say "\$rc=$rc";
    say $OS_ERROR;
    

  • $rc - 0. , script . $OS_ERROR.
  • , script , .
  • , .

, , script, exec -ing script, , , . , script.

qx backticks (`) , shebangs (#!) perl script script.

0

[ 127.0.0.1] script:

pl ( , ) . :

#!c:/wamp/bin/perl/bin/perl.exe

print "Content-type: text/html\n\n";
print "<html><head><title>Test</title></head>";
print "<body>";
print "Hello";
print "</body></html>";

###

, : print "Content-type: text/html\n\n"; < -

Grettings

0

qx :

my @array = qx(ls -1);

, , qx , , 4 , .

-2

All Articles