my $pid = fork(); if($pid == 0) { my $log = '/home/tart/tmp/log.log'; open(CLOG, ">>$log") || die "$0: can't open '$log': $!\n"; open(STDOUT, ">&CLOG")|| die "$0: Can't remap STDOUT: $!\n"; open(STDERR, ">&CLOG")|| die "$0: Can't remap STDERR: $!\n"; @systemOut = `$command`; print CLOG "@systemOut"; close CLOG; exit $?; } else { while (waitpid($pid, WNOHANG) == 0) { sleep 1; my $upTime = time; my $diffTime = $upTime - $sTime; $diffTime = int($diffTime/60); verbose($configHR, "Processing...since $diffTime Min!") if($diffTime != $regVal); $regVal = $diffTime; } } if($? == 0) { print LOG "Status: Success\n"; return 1; } print LOG "Status: Failed While Executing $command\n"; #### #$sub is subroutine name. #for example: $sub = '&execute'. my $stmt = '$rv = '. $sub; eval $stmt; if($@) { print $@, "\n"; } sub execute { my $pid = fork(); if($pid == 0) { my $log = '/home/tart/tmp/log.log'; open(CLOG, ">>$log") || die "$0: can't open '$log': $!\n"; open(STDOUT, ">&CLOG")|| die "$0: Can't remap STDOUT: $!\n"; open(STDERR, ">&CLOG")|| die "$0: Can't remap STDERR: $!\n"; @systemOut = `$command`; print CLOG "@systemOut"; close CLOG; exit $?; } else { while (waitpid($pid, WNOHANG) == 0) { sleep 1; my $upTime = time; my $diffTime = $upTime - $sTime; $diffTime = int($diffTime/60); verbose($configHR, "Processing...since $diffTime Min!") if($diffTime != $regVal); $regVal = $diffTime; } } if($? == 0) { print LOG "Status: Success\n"; return 1; } print LOG "Status: Failed While Executing $command\n"; }