Xantara has asked for the wisdom of the Perl Monks concerning the following question:
Hi all,
I was wondering if someone could lend me a solution. :(
I have a list of commands (user defined perl module subroutine) in a text file, that my script reads in one at a time, and then I try to execute as below.
eval $cmd
Each command will wait for response for 90sec to go for next command.
Here one of my command should not wait for the response to go further commands.
I tried as below but failed by getting a popup menu:
Also I got error in the Perl cmd prompt:Attempt to free unreferenced scalar"Perl Command Line Interpreter has encountered a problem and needs to +close"
$cmd will be holding commands like MCI->Do("SETP NAS_R99_QOS 0");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 recogn +ised by MCI... # Engine provides a 'Wait' function, but sometimes 'Wait' is i +n 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 90sec +s.\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 f +ailed\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 fro +m 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 =~ /O +K/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 accordi +ngly. $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; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: eval a command
by tmharish (Friar) on Feb 21, 2013 at 14:13 UTC | |
by Xantara (Initiate) on Feb 21, 2013 at 14:56 UTC | |
by tmharish (Friar) on Feb 22, 2013 at 06:40 UTC | |
by marto (Cardinal) on Feb 22, 2013 at 09:54 UTC |
Back to
Seekers of Perl Wisdom