perl Net::Telnet wait_for 中间字符,而“print”则为中间字符。操作仍在缓冲数据
我将 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里的问题可能是,即使在调用
buffer_empty
之后,cmd 1
仍在填充输入缓冲区。如果您知道cmd 1
输出的最后是什么,最好的解决方案是添加另一个waitfor
以确保“cmd 1”在发出之前已完成运行'命令2'。另一种选择是在调用
buffer_empty
之前添加sleep
。The problem here might be that
cmd 1
is still filling the input buffer even afterbuffer_empty
is called. If you know what is at the very end of output ofcmd 1
, the best solution would be to add anotherwaitfor
to make sure 'cmd 1' has finished running before issuing 'cmd 2'.Another option would be to add
sleep
before callingbuffer_empty
.