in reply to How to grab the telnet screen output?

Hi,

You'll need to use the waitfor and print (Net::Telnet) to process the initial menus. Something like this ...

$telnet->waitfor(Match => m{$last_line_of_the_1st_menu}smx); $telnet->print(q{a}); $telnet->waitfor(Match => m{$last_line_of_the_2nd_menu}smx); $telnet->print(q{b});
For debugging, and you'll need it, use the input_log, to see all the interaction with the NetGear switch.

Replies are listed 'Best First'.
Re^2: How to grab the telnet screen output?
by phio (Acolyte) on Jan 29, 2008 at 02:40 UTC
    Thanks:-)

    I forgot to mention that I was using Net::Telnet module. Now the problem is kind of fixed, but some wired problem just remain :-(

    I use get to get the content of sub menu, and remove the telnet control sequences, then have the clean and tidy text manipulated.

    The problem is that I can not use getline, or getlines, they offer nothing to me. And I can not use waitfor because the last several lines of the control menu are all same, so...

    And also, I found that Net::Telnet may have some problem in dealing with TCP packets, sometime it just mis-treat a packet end as a EOF and return the incomplete content to me when there are still some packets to read. The timeout value is enough for it, I am sure.

      Hi,

      Normally, I use the waitfor to match a temporary changed "prompt", like a --more--. And, as you can read in the Net::Telnet with

      ($prematch, $match) = $obj->waitfor($matchop); $obj->print(q{a}) if( $prematch =~ m{f\. Advanced}sm ); $obj->print(q{b}) if( $prematch =~ m{l\. Command Line}sm );
      you can use the $prematch to get the context.

      Probably, your problem it's not with the TCP packets and the Net::Telnet, but with a premature match. Use the dump_log to inspect the flow of the session, and last, but not the least, use the perl -d to check each telnet interaction.