Perl script hangs for no reason

So I have this little script that checks two log files for a specific string and compares the strings. The script is used for several different Windows Bamboo agents. But on one he just hangs and does not come out. Since the script is used in bamboo, all work hangs when this script doesn't exit. When I check the computer using remote access and kill the script, it continues working until it reaches the script again.

This is a script that is run by another script.

#! /usr/bin/perl
my $naluresult = 2;
my $hevcresult = 2;
my $hevcfailed = 0;

use strict;
use warnings;

#---------------------------------------------
#check for $ARGV[0] and $ARGV[1]

open( my $nalulog, "<", $ARGV[1] )
    or die "cannot open File:$!\n\n";
while (<$nalulog>) {
    chomp;
    $_ =~ s/\s+//g;
    if ( $_ =~ m/MD5:OK/ ) {
        $naluresult = 1;
    } else {
        if ( $_ =~ m/MD5:MISSING/ ) {
            $naluresult = 0;
        }
    }
}
close $nalulog;

#---------------------------------------------

open( my $hevclog, "<", $ARGV[0] )
    or die "cannot open File:$!\n\n";

while (<$hevclog>) {
    chomp;
    $_ =~ s/\s+//g;
    if ( $_ =~ m/MD5check:OK/ ) {
        $hevcresult = 1;
        last;
    } else {
        if ( $_ =~ m/MD5check:FAILED/ ) { $hevcfailed = 1; }
    }
    if ( $hevcfailed == 1 ) {
        #do stuff
    }
}
close $hevclog;

#---------------------------------------------

if ( $hevcresult == 2 ) {
    print("Missing MD5 status in HEVC Output");
    exit(-1);
} elsif ( $naluresult == 2 ) {
    print("Missing MD5 status in NALU Output");
    exit(-2);
} else {
    if ( $naluresult == $hevcresult ) { exit(0); }
    else {
        #different if-statements to print() to log
        exit(1);
    }
}

#---------------------EOF---------------------

      

+3


source to share


1 answer


If your files are just regular files on disk that are not being written at the same time by other processes or locked or something like that, then there is nothing in the code you are here that should hang. If the files are the same size, then the code you have should read the files and finish.



However, if one of the files is locked or very large, or if you have other code that might get stuck in an infinite loop, this explains why your program is hanging.

0


source







All Articles