Howdy, Stranger!

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

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.