cspctec has asked for the wisdom of the Perl Monks concerning the following question:
Hi, I am trying to write a script that will connect to the telnet port on my device, send a command, and get the reply back. My script is currently not returning the result of the command I send.
#!/usr/bin/perl use strict; use warnings; use IO::Socket; my ($host, $port) = ('111.111.111.111', '23'); my $command = "\$TEMP*"; my $socket = new IO::Socket::INET ( PeerAddr => $host, PeerPort => $port, Proto => 'tcp', ); if (!$socket) { die "Unable to establish connection to $host\n"; } print $socket $command; $socket->getline; my $output = <$socket>; $socket->close; print "$output\n";
So the script is suppose to open a socket on port 23, send the command $TEMP* and then get the result that the device will give. The script either hangs or it just returns the "Welcome to device 'devicename', please input your commands".
Is there anyway to make the script wait and grab the output after the command $TEMP* is input? The device is suppose to return something like $TEMP*,42C.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Getting a response from a socket
by 7stud (Deacon) on Feb 13, 2013 at 23:50 UTC | |
Re: Getting a response from a socket
by NetWallah (Canon) on Feb 14, 2013 at 03:42 UTC | |
Re: Getting a response from a socket
by VinsWorldcom (Prior) on Feb 14, 2013 at 00:25 UTC | |
by cspctec (Sexton) on Feb 14, 2013 at 15:27 UTC |
Back to
Seekers of Perl Wisdom