Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Perl code runs from command line, but not CGI script

jblockjblock Posts: 1Member
Can anyone help me understand why this code runs from the command line but not from a cgi script? When I type:

perl myscript.pl

at the Linux command line, it runs perfectly. But when I embed the code in a cgi script and call it from a web form it does not run. I don't get a syntax error, I just do not get the mail. I don't think it's an
environmental problem. My script sets all the required environment variables and paths, so the cgi knows where sendmail is, etc. Any ideas? Thanks.

Assume $cleartext1 and $recipient are set. Also assume that cgi has appropriate #!/usr/bin/perl in the header, etc. (ie, all the simple stuff is covered).


# Load Open2 module for bi-directional I/O
use IPC::Open2;

&cat_order;
&send_order;

sub cat_order {

# Set up the cat command
$catcmd = "cat -u";

# Open the cat program for bidirectional I/O
$pid = open2(*READER, *WRITER, $catcmd) || die "Can't open cat: $!
";

# Send text to cat
print WRITER $cleartext1;

# Send the data
close(WRITER);

# Get the data from cat
@cattext = ;
close(READER);

}


sub send_order {

# Open The Mail Program
open (MAIL, "|$mailprog $recipient") || die "Can't open $mailprog: $!
";

# Standard headers
print MAIL "From: Administrator
";
print MAIL "To: $recipient
";
print MAIL "Subject: In-Line ClearText Test

";

print MAIL @cattext;

close (MAIL);

}

Comments

  • WeirdofreakWeirdofreak Posts: 439Member
    The obvious thing would be to check the permissions. It'll need execute capabilities for the user.
  • JonathanJonathan Posts: 2,914Member
    : The obvious thing would be to check the permissions. It'll need
    : execute capabilities for the user.
    Agree. At the command line type:-

    chmod 755 thescript.pl

    That should sort the permissions issue. The other thing that stands out is you don't seem to print any output, or at least a HTTP header saying there will be no output. You should do something like:-

    print "Content-type: text/html

    ";
    print "other stuff...";

    Or there is a response header you can print that says there is no output to come. You must print at least one valid HTTP header though.

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

Sign In or Register to comment.