我正在为我的网站使用CGI脚本。我打开动态生成的文件时遇到问题。这是代码:
#!/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...
总是失败,输出:
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.
虽然这成功了:
#!/usr/bin/perl
open(my $result, "<", /var/tmp/notification-finder-1375086676-658183725.tmp) or die "Can't open $filen - $!";
Do something with the file...
我还检查了是否是异步执行反引号问题的问题,但是根据我对stackoverflow的研究,它似乎不是问题。我也试过这个:
#!/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...
我找到了这个similar issue here,但我似乎没有提问者那样的问题......感谢您阅读这篇文章。
答案 0 :(得分:4)
错误表示$filen
末尾有换行符,否则会出现:
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.
删除它:
chomp $filen;