in reply to telnet from telnet

I had lots of problems with your code. Here is what I got to work.
use strict; use Net::Telnet; $b = Net::Telnet->new( Output_record_separator => '', Prompt => '/\$ $/', Timeout => 20, Host => 'localhost', ); $b->login("guest\n", "testme\n") or die "Connect failed: @{ $b->errmsg +() }\n"; my @output = $b->cmd("who\n"); print "out @output\n"; @output = $b->cmd(q[ perl -w <<EOP use Net::Telnet; my \$c = Net::Telnet->new( Errmode => 'return', Telnetmode => 1, Output_record_separator => '', Prompt => '/\\\$ $/', Timeout => 10, Host => 'localhost' ); \$c->login( "guest\n", "testme\n" ) or die "Connect failed: @{ \$c->errmsg() }\n"; my @output = \$c->cmd("who\n"); print "out @output\n"; EOP ]); print "out @output\n";
You need to change 'localhost', 'guest', and 'testme'.

UPDATE: did not have enought escaping. The prompt argument seems to be problematic.

-- gam3
A picture is worth a thousand words, but takes 200K.

Replies are listed 'Best First'.
Re^2: telnet from telnet
by Anonymous Monk on Apr 12, 2005 at 13:57 UTC
    Thanks for your effort.
    But, the code does not work.
    I tried to print with the $c and it says cmd method not defined.
    But, as with the original code, you can print from
    from $b.