views:

34

answers:

1

I'm using perl with the Net::Telnet module.

My problem is while sending a command that has an output of 1000 rows, the "wait_for" looks for a string in the middle.

The wait_for stops but the buffer is still keeps storing the command's output.

the problem is with the next command that I send - I'm getting the rest of the first command's output.

#!/usr/bin/perl
use Net::Telnet;

$session = new ... ();
$session->print("cmd 1");
my $output = $session->wait_for(String => "AAA");

$session->buffer_empty;
$session->print("cmd 2");
my $output2 = $session->wait_for(String => "#");

I've tried sending a "$session->buffer_empty" but it doesn't help. Does anyone have any idea what is happening here?

+1  A: 

The problem here might be that cmd 1 is still filling the input buffer even after buffer_empty is called. If you know what is at the very end of output of cmd 1, the best solution would be to add another waitfor to make sure 'cmd 1' has finished running before issuing 'cmd 2'.

#!/usr/bin/perl
use Net::Telnet;

$session = new ... ();
$session->print("cmd 1");
my $output = $session->wait_for(String => "AAA");

$session->wait_for(Match => '/>$/');
$session->buffer_empty;

$session->print("cmd 2");
my $output2 = $session->wait_for(String => "#");

Another option would be to add sleep before calling buffer_empty.

thaedal
You're right, i didn't though of that. but the command is an argument, and not all the commands have to wait twice. so this solution might stuck the script. with ->getlines(<timeout>) - it doesn't metter if i have another data or not. it simply wait for X seconds and then keep going ....
Ricky