-1

I have a perl script which i am running in daemon mode with the following code.

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 });

The RandomPackage::GetContent has the following definition.

use File::Temp;
sub GetContent {
   my ($args) = @_;
   my ($filehandle, $filename) = File::Temp::tempfile();

   open $filehandle, ">", $filename or "cant open the filehandle";
   <Some operations>
   return ;
 }

While running the script in daemon mode, I get the error cant open the filehandle. Any help is appreciated.

aman
  • 365
  • 3
  • 13
  • What error did `open` return? Replace `or "cant open the filehandle"` with `or die("Can't open the \"$filename\": $!\n");` – ikegami Aug 21 '17 at 22:21
  • That's not how File::Temp should be used. `$filehandle` already contains an open handle to `$filename`. – ikegami Aug 21 '17 at 22:22
  • Keep in mind that Proc::Daemon::Init tries to closes every file handle your process owns except those you tell it not to close. – ikegami Aug 21 '17 at 22:23
  • "cant open the filehandle" – aman Aug 22 '17 at 05:34
  • Nope, that's not an error returned by `open`. Perhaps you should read my comment again: What error did `open` return? To find out, replace `or "cant open the filehandle"` with `or die("Can't open the \"$filename\": $!\n");` – ikegami Aug 22 '17 at 05:54

1 Answers1

0

Most likely it is a permission error.

Print the contents of $! it will inform you of the type of error.

rouzier
  • 1,160
  • 8
  • 19