【发布时间】:2017-08-21 18:42:25
【问题描述】:
我有一个 perl 脚本,我正在使用以下代码在守护程序模式下运行。
Proc::Daemon::Init()
# Anonymous subroutine.
my $sub = sub {
# Call to the function which opens the filehandle
my $content = RandomPackage::GetContent({ $args});
}
# Forking
Proc::ForkAndForget->({JOB => $sub });
RandomPackage::GetContent 具有以下定义。
use File::Temp;
sub GetContent {
my ($args) = @_;
my ($filehandle, $filename) = File::Temp::tempfile();
open $filehandle, ">", $filename or "cant open the filehandle";
<Some operations>
return ;
}
在守护程序模式下运行脚本时,我收到错误无法打开文件句柄。 任何帮助表示赞赏。
【问题讨论】:
-
open返回了什么错误?将or "cant open the filehandle"替换为or die("Can't open the \"$filename\": $!\n"); -
File::Temp 不应该这样使用。
$filehandle已经包含到$filename的打开句柄。 -
请记住,Proc::Daemon::Init 会尝试关闭您的进程拥有的每个文件句柄,但您告诉它不要关闭的文件句柄除外。
-
"无法打开文件句柄"
-
不,这不是
open返回的错误。或许你应该再看一遍我的评论:open返回了什么错误?要找出答案,请将or "cant open the filehandle"替换为or die("Can't open the \"$filename\": $!\n");
标签: perl daemon filehandle