Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Net::Telnet and telnet command output

by Rhys (Pilgrim)
on Oct 04, 2004 at 12:32 UTC ( #396204=note: print w/ replies, xml ) Need Help??


in reply to Net::Telnet and telnet command output

There are three ways, all of which are documented in the perldocs for Net::Telnet. The first is to just grab the return values from the cmd method:

use Net::Telnet (); $t = new Net::Telnet (Timeout => 10, Prompt => '/bash\$ $/'); $t->open("sparky"); $t->login($username, $passwd); @lines = $t->cmd("who"); print @lines;

The second is to grab the raw input from the telnet stream (not recommended) that has already arrived:

$ref = $obj->buffer;

The third is to go and grab new raw data on its way in:

$data = $obj->get([Binmode => $mode,] [Errmode => $errmode,] [Telnetmode => $mode,] [Timeout => $secs,]);

The getline and getlines methods are probably much easier to deal with than get, and work on the same principles.

I highly recommend reading the perldoc info on Net::Telnet very thoroughly, even though it is rather tedious. I learn something every time I read it. I also recommend using the debugging/logging methods for a while. I have found them to be invaluable when trying to figure out why my patterns are(n't) matching some weird binary input. (The buffer_empty method is your friend.)

Hope that helps!

--J


Comment on Re: Net::Telnet and telnet command output
Select or Download Code
Re^2: Net::Telnet and telnet command output
by sashac88 (Beadle) on Oct 04, 2004 at 17:56 UTC
    The problem is that neither solution works.
    I've tried all of them already.
    That's why I asked here.
    Is there anything else I can try?
    I guess the problem is that the switch doesn't act like
    the regular operating system
    .

      Perhaps if you showed us your current script and explained what it was doing wrong we could help better.


      ___________
      Eric Hodges

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://396204]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (9)
As of 2014-07-30 20:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (240 votes), past polls