perl Net::Telnet wait_for 中间字符,而“print”则为中间字符。操作仍在缓冲数据

发布于 2024-09-29 02:35:58 字数 597 浏览 3 评论 0原文

我将 Perl 与 Net::Telnet 模块一起使用。

我的问题是,在发送输出为 1000 行的命令时,“wait_for”会在中间查找字符串。

wait_for 停止,但缓冲区仍继续存储命令的输出。

问题在于我发送的下一个命令 - 我正在获取第一个命令的其余输出。

#!/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 => "#");

我尝试发送“$session->buffer_empty”,但没有帮助。有谁知道这里发生了什么吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

颜漓半夏 2024-10-06 02:35:58

这里的问题可能是,即使在调用 buffer_empty 之后,cmd 1 仍在填充输入缓冲区。如果您知道 cmd 1 输出的最后是什么,最好的解决方案是添加另一个 waitfor 以确保“cmd 1”在发出之前已完成运行'命令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 => "#");

另一种选择是在调用 buffer_empty 之前添加 sleep

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文