Perl

Moderators: Jonathan
Number of threads: 1236
Number of posts: 3605

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Perl code runs from command line, but not CGI script Posted by jblock on 15 Dec 2003 at 12:59 PM
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: $!\n";

# Send text to cat
print WRITER $cleartext1;

# Send the data
close(WRITER);

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

}


sub send_order {

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

# Standard headers
print MAIL "From: Administrator \<admin\@mysite.com\>\n";
print MAIL "To: $recipient\n";
print MAIL "Subject: In-Line ClearText Test\n\n";

print MAIL @cattext;

close (MAIL);

}
Report
Re: Perl code runs from command line, but not CGI script Posted by Weirdofreak on 15 Dec 2003 at 1:08 PM
The obvious thing would be to check the permissions. It'll need execute capabilities for the user.
Report
Re: Perl code runs from command line, but not CGI script Posted by Jonathan on 15 Dec 2003 at 2:50 PM
: 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\n\n";
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.");




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.