2

我正在为我的网站使用 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...

我在这里发现了类似的问题,但我似乎没有与提问者相同的问题......感谢您阅读本文。

4

1 回答 1

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;
于 2013-07-29T09:18:34.117 回答