Hi there
I'm having some trouble with a cgi script. I'm getting the 'Premature End of Script Headers' error message and it's getting to be very frustrating.
This is a test script at present. The input_file variable will eventually be passed to the script via another one ... but for the moment its being invoked via redirection from a html page.
Basically, it runs an executable (a C program) using the input_file as input. It results in the generation of a number of text files.
When run locally from the command line, the executable program does print to STDOUT so I was wondering whether this may be causing my error. Anyway, this is the script as is (which by the way has been developed with the kind help from a perl monk already).
#!/usr/bin/perl
use strict;
use warnings;
use CGI qw/:standard/;
# Upload directory for files
my $upload_dir = "uploadpath";
# Path to processing program
my $program = "path/processprogram";
my $input_file = "inputfile.txt";
die "Usage: $0 INPUT_FILENAME\n" unless $input_file;
die "Can't process '$upload_dir/$input_file': File does not exist!\n"
unless -f "$upload_dir/$input_file";
# Create web page...
print header,
start_html("Processing file '$input_file' ..."), $/,
h1("Processing file '$input_file' ..."), $/;
chdir $upload_dir;
open (PROG, "| $program") || die "Can't run '$program': $!\n";
print PROG "$input_file\n";
close(PROG);
print p("OK"), end_html();
Any comments, suggestions much appreciated
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.