开发者

Perl Module Telnet: Problem with Cd (changing directory)

开发者 https://www.devze.com 2023-03-27 12:40 出处:网络
I am trying to use the Net::Telnet module to set up testing automation. My test relies on the changing directories and executing test.

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 2开发者_开发问答0 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



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

0

精彩评论

暂无评论...
验证码 换一张
取 消