I have a cgi-script that is supposed to run another script via system and then open a txt file to read two lines of data. All is fine until it tries to open the file.
In both terminal and browser I get the error message 'No such file or directory.'
No amount of googling or searching the archives in the Monastery has helped me.
As far as I can tell the file is valid because:
- I have checked the file's existence and permissions manually in the file system and using -e, -w and -r in the script.
- The file in question is opened by the second script that is called. (I get the same message when the second script is not called so I am confident it relates to the attempt to open the file for reading in this script.)
The script follows including the test for the file which is really only for troubleshooting:
#!/usr/bin/perl -w
use lib "/usr/local/lib/perl/lib/perl5/site_perl/5.8.8";
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use strict;
print header;
my ($x, $y);
my $datafile = "/full/path/to/file/data.txt";
system("perl /full/path/to/file.cgi")==0 or die "system failed $?"
+;
if(!(-w $datafile)){
print "What file?<br>";
}
else{
open (FILE, '<', '$datafile') || die "Could not read $datafile $!\
+n";
$x = <FILE>;
$y = <FILE>;
close (FILE);
}
print $x."<br>";
print $y."<br>";
I'd appreciate any thoughts on why the same script is getting different results in relation to exactly the same file.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.