Perl 模块 Telnet:Cd 问题(更改目录)
我正在尝试使用 Net::Telnet 模块来设置测试自动化。我的测试依赖于更改目录和执行测试。
这是代码
use warnings;
use strict;
use Net::Telnet;
my $telnetObject = Net::Telnet->new(Timeout => 10);
$telnetObject->open("10.30.16.113");
$telnetObject->waitfor('/login/');
$telnetObject->print("john");
$telnetObject->waitfor('/{\d+}/');
#
my $fh = $telnetObject->input_log("output.txt");
$telnetObject->prompt('/{\d+}/');
$telnetObject->cmd_remove_mode(1); # omit command echo from output
$telnetObject->print('cd test/displayBlock');
my @lines2 = $telnetObject->waitfor('/{\d+}/');
print @lines2;
,这是输出日志:
> 0x00000: 63 64 20 74 65 73 74 2f 64 69 73 70 6c 61 79 42 cd test/displayB
> 0x00010: 6c 6f 63 6b 0d 0a lock..
< 0x00000: 63 64 20 74 65 73 74 2f 64 0d 3c 64 20 74 65 73 cd test/d.<d tes
< 0x00010: 74 2f 64 69 20 20 20 20 20 20 20 20 20 20 20 20 t/di
< 0x00020: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
< 0x00030: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
< 0x00040: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
< 0x00050: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
< 0x00060: 20 20 20 0d 3c 64 20 74 65 73 74 2f 64 69 73 70 .<d test/disp
< 0x00070: 6c 61 79 42 6c 6f 63 6b 0d 0a layBlock..
< 0x00000: 3c <
出于某种原因,它在最后一个 waitfor 命令处超时。
请帮忙:(
谢谢
I am trying to use the Net::Telnet module to set up testing automation. My test relies on the changing directories and executing test.
This is the code
use warnings;
use strict;
use Net::Telnet;
my $telnetObject = Net::Telnet->new(Timeout => 10);
$telnetObject->open("10.30.16.113");
$telnetObject->waitfor('/login/');
$telnetObject->print("john");
$telnetObject->waitfor('/{\d+}/');
#
my $fh = $telnetObject->input_log("output.txt");
$telnetObject->prompt('/{\d+}/');
$telnetObject->cmd_remove_mode(1); # omit command echo from output
$telnetObject->print('cd test/displayBlock');
my @lines2 = $telnetObject->waitfor('/{\d+}/');
print @lines2;
And here is the output log is :
> 0x00000: 63 64 20 74 65 73 74 2f 64 69 73 70 6c 61 79 42 cd test/displayB
> 0x00010: 6c 6f 63 6b 0d 0a lock..
< 0x00000: 63 64 20 74 65 73 74 2f 64 0d 3c 64 20 74 65 73 cd test/d.<d tes
< 0x00010: 74 2f 64 69 20 20 20 20 20 20 20 20 20 20 20 20 t/di
< 0x00020: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
< 0x00030: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
< 0x00040: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
< 0x00050: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
< 0x00060: 20 20 20 0d 3c 64 20 74 65 73 74 2f 64 69 73 70 .<d test/disp
< 0x00070: 6c 61 79 42 6c 6f 63 6b 0d 0a layBlock..
< 0x00000: 3c <
For what Ever reason, the it times out at at the last waitfor command.
Please help :(
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这里的根本问题是您缺少回车符 (\r)
通常当您与 telnet 等终端交互时,您会注意到每次按一个键时,终端都会回显使用相同的 ASCII 字符的密钥。如果您使用 screen 等程序,并打开日志记录,您确实可以看到使用 \r\n 回显返回键。这就是您解决这个问题的方法。
谢谢
希望这有帮助
I think the underlying problem here is that you are missing a carriage return (\r)
Usually when you are interacting with a terminal such as telnet you will notice that each time you press a key, the terminal echos the key using a equal ascii character. If you use a program such as screen, and turn on logging, you can indeed see that a return key will be echoed using \r\n. That is how you will solve this problem.
Thank You
Hope this Helps