[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 157
  • Last Modified:

background

for (my $i = 0; $i < @files; $i++) {
    chomp (my $date = `date '+%m%d%y-%H:%M:%S'`);
    $file = $files[$i] . "_$date";
    `mv -f $path/$files[$i] $path/$file`;

#    exec("(/usr/local/bin/perl $path/email.pl $file) ");

    $::SIG{INT} = 'IGNORE';  # c 'turn undead' zombies
    unless(fork) {
        open STDIN,  "</dev/null";
        open STDOUT, ">/dev/null";
        exec(" /usr/local/bin/perl  $path/email.pl $file 2 > $path/output &");
        exit;  # This block only executes if we're the child, so exit when we're done.
    }

}


i m running in background, but still when i run the above script, it erminates immidiately but  after that throws the output to prompt
0
shahrahulb
Asked:
shahrahulb
1 Solution
 
manav_mathurCommented:
-- It seems you are 'exec'ing over your parent, and not your child. The unless should be replaced by if.

--
> unless(fork)

doesnt distinguish between a failed fork and a parent process. You are better off using something like

my $pid ;
die("$! : Couldnt fork!!") unless defined($pid = fork) ;
if($pid) {
...
...
0
 
TintinCommented:
While we're at it, let's Perlise your very shell like code:

Change

for (my $i = 0; $i < @files; $i++) {
   chomp (my $date = `date '+%m%d%y-%H:%M:%S'`);
   $file = $files[$i] . "_$date";
   `mv -f $path/$files[$i] $path/$file`;

to

use POSIX qw(strftime);

foreach my $file (@files) {
  my $date = strftime '+%m%d%y-%T',localtime;
  rename "$path/$file $path/${file}_$date" or warn "Can not rename $path/$file $!\n";
}

BTW, you would be better using a sensible, unambiguous, universal date format, ie: YYYYMMDD




0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now