eval $cmd
####
"Perl Command Line Interpreter has encountered a problem and needs to close"
####
foreach (@commands) {
$cmd = $_;
if($cmd =~ /PLA_ENABLE/i){
$pid = fork();
if (defined $pid && $pid == 0) {
# child
eval $cmd;
}
exit 0;
}
else{
eval $cmd;
}
}
####
sub Do {
my ($self, $cmd, $time_out) = @_;
my ($TimeOut, @lines, $StopTime);
my ($prematch, $result, $retVal);
my ($success, @reply);
my $nice = 0;
my $linecount = 0;
tie $retVal, 'ReturnValue';
$retVal = PASS;
# Empty the input buffer
$self->{_tnet}->buffer_empty;
# Clear the last error message
$self->{_tnet}->errmsg(@reply);
#cut newline if there is one
chomp $cmd;
print $gLog Text => "$cmd\n", Name => $self->{_name};
if ($cmd =~ /Wait/) {
# MDL 'Wait' command can be used in scripts, but is not recognised by MCI...
# Engine provides a 'Wait' function, but sometimes 'Wait' is in a TM script and does not get
# sent to the Engine 'Wait' function because it doesn't end in a semicolon.
$cmd =~ s/^\s+//;
my $waittime = ${[split /\s+/, $cmd]}[1];
return $gEngine->Wait($waittime);
}
#If time out is defined this sets the time out.
if (defined($time_out)) {
if ($time_out =~/^[0-9]+$/) {
$TimeOut = $time_out;
} else {
print $gLog Text => "Invalid time out provided using 90secs.\n", Color => "blue", Name => $self->{_name};
$TimeOut = 90;
}
} else {
$TimeOut = 90;
}
$_ = $cmd;
# SCFG timeout is 15 minutes.
/SCFG/i && do { $TimeOut = 900; $nice = 1; };
# initcellsearch timeout is now 60 seconds.
/initcellsearch/i && do { $TimeOut = 60; };
# Send command.
$self->{_tnet}->timeout(1);
$success = $self->{_tnet}->print( $cmd );
if (!$success) {
print $gLog Text => "Sending the command $cmd to the mobile failed\n", Color => "red", Name => $self->{_name};
return $self->_checkfailures($cmd);
}
$StopTime = time + $TimeOut;
# Wait for reply - matches the presence of a 'C:'
$result = "";
WAIT: {
do {
undef @lines;
_sleep_for(0.05) if ($nice);
@lines = $self->{_tnet}->getlines(TimeOut => 0);
foreach $prematch (@lines) {
push @reply, $prematch;
$result .= $prematch;
}
if (time > $StopTime) {
print $gLog Text => "Confirmation C: not received from mobile in $TimeOut seconds. Checking for errors.\n", Color => 'red', Name => $self->{_name};
$retVal = $self->_checkfailures($cmd);
last WAIT;
}
} until (($result =~ /C:\s*(\w+)\s*0x\d\d/i) || ($result =~ /OK/i));
}
# Count the number of lines received in the WAIT loop.
$linecount = @reply;
if ($linecount > 0) {
# Print the line. Scan it for errors and set the state accordingly.
$retVal = $self->_printReturnedLines($result);
} else {
# Fatal error as no lines were received.
$retVal = FATAL;
}
return $retVal if (($retVal == FATAL) || ($retVal == CRASH));
$retVal = $self->Pass_Conf_Ind(@lines, $cmd);
return wantarray ? ($retVal, $result) : $retVal;
}