我正在为我的网站使用 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 ,但我似乎没有与提问者相同的问题...感谢您阅读本文。
最佳答案
错误表明$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;
关于Perl 打开动态生成的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17919493/