开发者

perl Net::Telnet wait_for a middle character, while the "print" action still buffering data

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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜