|
Posted by Paul Lalli on April 6, 2006, 10:59 am
Please log in for more thread options
kishore.konjeti@gmail.com wrote:
> i had written code to connect to unix server from Windows xp(telnet)
> where i installed perl.
> i have to do with telnet. I think I am able to connect with unix
> server. but i am not able to get out put from the server. i have
> triedwith 'ls' and 'who' commands. But i am not able to getting any
> output from server.
> The code is :
>
You seem to have forgotten:
use strict;
use warnings;
> use Net::Telnet;
>
> # instantiate a new CGI object
> my $telnet = new Net::Telnet(Timeout => 10,
> Errmode => 'die');
>
>
> $telnet->open("servername") or die "hai $telnet->errmsg ";
errmsg() is a method, not a variable, and so does not interpolate. If
this die() were ever executed, you'd get something like:
hai Net::Telnet=HASH(0x123456)->errmsg
> print "connected";
> $telnet->waitfor('/login: $/i');
> $telnet->print("ixlourd") or die $telnet->errmsg;
> $telnet->waitfor('/password: $/i');
> $telnet->print("qwest1") or die $telnet->errmsg;
> print "logged in";
> $telnet->waitfor('/ixlourd\@e2epia2: $/');
> print "Before ls";
> $telnet->print('who');
> $telnet->waitfor('/ixlourd\@e2epia2: $/');
> #$output = $telnet->waitfor('/$ $/i');
> print $output;
> @lines=$telnet->print("ls") or die $telnet->errmsg;
What do you think this is doing?
Have you read the documentation for the module you're using, and the
specific documentation for the method you're using in that module?
perldoc Net::Telnet
print - write to object
$ok = $obj->print(@list);
This method writes @list followed by the
output_record_separator to the open object and returns
"1" if all data was successfully written.
> I have copied telnet.pm module from CPAN to perl directory.
That is not the way you install a Perl module
perldoc perlmodinstall
> why it is not giving any output of 'ls' . it is simply it is giving
> "connectedlogged inBefore ls"
because print() does not return the results of the command it sent to
the server.
Read the documentation for the module to learn what method you should
be using instead....
> How can i make check whether it is connected to my unix server
> successfully.
You're already doing that, by specifying the errmode() to 'die'
Paul Lalli
|