siddheshsawant has asked for the wisdom of the Perl Monks concerning the following question:

Hello everyone !!!!

I have written a simple following script:

#!/usr/bin/perl -w use CGI qw(:standard); use CGI::Carp qw(warningsToBrowser fatalsToBrowser); print header; print start_html("Thank You"); my $test_input = 2; my $cmd=`perl -n /tmp/test.pl $test_input > /pptai/nightly_db/api.out` +; my $resdir = "/pptai/nightly_db/api.out"; open RES, $resdir or die "Couldn't open file $resdir: +$!\n"; print end_html;

And the corresponding perl is as follows

#!/usr/bin/perl -w use strict; if($ARGV) { my $input=$ARGV; print "This is number ".$input; }

I am getting an error like this

Software error:

Couldn't open file /pptai/nightly_db/api.out: No such file or directory

Kindly let me know where I am doing mistake....

Thanks in advance .....

Replies are listed 'Best First'.
Re: calling perl file subroutine from CGI script
by Corion (Patriarch) on Mar 05, 2010 at 17:40 UTC

    The error message says that /pptai/nightly_db/api.out does not exist. So likely, the file /pptai/nightly_db/api.out does not exist. Which, by induction, would mean that the command perl -n /tmp/test.pl $test_input > /pptai/nightly_db/api.out failed. You don't capture the error output of your command, so it's kinda hard to tell why the file is not created, but most likely, that is a permissions issue, likely because the user your script is running under is not the user that is allowed to access /tmp/test.pl or something like that. Look in your webserver error log for further information.