I am using CGI script for my website. And I have problem with opening a dynamically generated file. Here is the code:
#!/usr/bin/perl
my @output = `/export/es_share/Zhou/./notification_finder.sh range $date $time $range $ulh TestProd1 $actionname`;
my $filen = $output[0];
open(my $result, "<", $filen) or die "Can't open $filen - $!";
Do something with the file...
Always fails, with the output:
Can't open /var/tmp/notification-finder-1375086676-658183725.tmp -
No such file or directory at /var/www/cgi-bin/appsupport/logapp_test/perltest.cgi line X.
While as this succeeds:
#!/usr/bin/perl
open(my $result, "<", /var/tmp/notification-finder-1375086676-658183725.tmp) or die "Can't open $filen - $!";
Do something with the file...
I have also checked if it was the problem of asynchronous execution of the backticks problem, but from my research on stackoverflow it does not seem to be the issue. I also tried this:
#!/usr/bin/perl
my @output = `/export/es_share/Zhou/./notification_finder.sh range $date $time $range $ulh TestProd1 $actionname`;
sleep(10);
my $filen = $output[0];
open(my $result, "<", $filen) or die "Can't open $filen - $!";
Do something with the file...
I have found this similar issue here, but I don't seem to have the same problem as the asker... Thanks for reading this far.
The error indicates there is a newline on the end of $filen
, otherwise it would be:
Can't open /var/tmp/notification-finder-1375086676-658183725.tmp - No such file or directory at /var/www/cgi-bin/appsupport/logapp_test/perltest.cgi line XXXXXXXXX.
Remove it with:
chomp $filen;