【问题标题】:Perl Module Telnet: Problem with Cd (changing directory)Perl 模块 Telnet:CD 问题(更改目录)
【发布时间】:2011-12-26 11:38:49
【问题描述】:

我正在尝试使用 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                                                  <

出于什么原因,它在最后一个等待命令时超时。

请帮忙:(

谢谢

【问题讨论】:

  • 您需要先接受一些关于您之前的问题的答案,然后才能获得很多帮助。
  • 这个telnet服务没有密码?
  • 真的没人,来个简单的问题。用一个简单的解决方案
  • 请帮忙!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!>>>>>>> >??????????????????????

标签: perl testing telnet


【解决方案1】:

我认为这里的根本问题是您缺少回车符 (\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');

谢谢你 希望这会有所帮助

【讨论】:

  • 您先生是个天才,您应该获得诺贝尔奖。
猜你喜欢
  • 1970-01-01
  • 2014-01-27
  • 1970-01-01
  • 2018-04-04
  • 1970-01-01
  • 1970-01-01
  • 2019-02-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多