in reply to Re^3: Net::Telnet: how to detect an empty line...
in thread Net::Telnet: how to detect an empty line...

Hey thanks for your help pc88mxer. I've read through the relatively short documentation for IO::Socket::INET, and I can't get the code below to work. Unfortunately, I don't think I know enough about network programming and or perl to get much farther on my own. It's passing the unless test, and exiting. The process is running, and I can connect to it with telnet.
my @resp; my @all_resp; my $s = new IO::Socket::INET( PeerAddr => 'localhost', Peerport => 400 +0, Proto => 'tcp', Timeout => 4); print "before unless"; unless ($s) { die "unable to connect..." } sleep 1; # we are connected, so just start sending commands print $s "auth admin 555555\r\n"; sleep 1; @resp = <$s>; # expect one line response push (@all_resp, @resp); print $s "voo allowed_ips\r\n"; sleep 1; @resp = <$s>; push (@all_resp, @resp); print @all_resp;

Replies are listed 'Best First'.
Re^5: Net::Telnet: how to detect an empty line...
by Corion (Patriarch) on Feb 27, 2008 at 07:02 UTC

    Like pc88mxer already said, you need to know when to stop to read. Your code

    @resp = <$s>; # expect one line response

    will read from $s until your daemon stops or closes the socket, contrary to your comment that it will only read one line. Try it with the following code:

    @resp = (); while (defined $_ = <$s> and ! /^\s*$/) { warn "DEBUG: Got >$_<"; push @resp, $_; };

    The above loop will output some debug information and read until the next empty line. If something goes wrong, you will easily see that from the debug information ...