Howdy, Stranger!

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


Perl code runs from command line, but not CGI script

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


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;


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

# Get the data from cat
@cattext = ;


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);



  • WeirdofreakWeirdofreak Member Posts: 439
    The obvious thing would be to check the permissions. It'll need execute capabilities for the user.
  • JonathanJonathan Member Posts: 2,914
    : 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

    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.


    (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.