【问题标题】:Unable to open a filehandle in a Proc::Daemon::Init'd script in perl无法在 perl 的 Proc::Daemon::Init'd 脚本中打开文件句柄
【发布时间】: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


【解决方案1】:

很可能是权限错误。

打印 $! 的内容它会通知您错误的类型。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-09
    • 2022-11-10
    • 1970-01-01
    相关资源
    最近更新 更多