Perl 模块 Telnet:Cd 问题(更改目录)

发布于 2024-11-29 04:45:27 字数 1627 浏览 0 评论 0原文

我正在尝试使用 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 技术交流群。

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

发布评论

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

评论(1

油焖大侠 2024-12-06 04:45:27

我认为这里的根本问题是您缺少回车符 (\r)


通常当您与 telnet 等终端交互时,您会注意到每次按一个键时,终端都会回显使用相同的 ASCII 字符的密钥。如果您使用 screen 等程序,并打开日志记录,您确实可以看到使用 \r\n 回显返回键。这就是您解决这个问题的方法。

$telnetObject->prompt('/{\d+}/');
$telnetObject->cmd_remove_mode(1); # omit command echo from output
$telnetObject->print('cd test/displayBlock\r');

谢谢
希望这有帮助


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.

$telnetObject->prompt('/{\d+}/');
$telnetObject->cmd_remove_mode(1); # omit command echo from output
$telnetObject->print('cd test/displayBlock\r');

Thank You
Hope this Helps

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