If you aren't interested in the gory details of sockets, Net::Telnet might be interesting for you.

Here's an example that does what I think you want. It doesn't read character by character, but it does print output as it reaches the buffer, rather than waiting for a newline:

#!/usr/bin/perl # unbuffer STDOUT, so you can watch the # traceroute output "realtime" select STDOUT;$|=1; use Net::Telnet; my($host)="yourhost"; my($trace)="www.cnn.com"; my($username)="username"; my($passwd)="password"; my($t)=Net::Telnet->new(Host => $host); defined($t) or die; $t->login($username, $passwd) or die; $t->print("traceroute $trace") or die; while (defined($data = $t->get())) { print $data; # supposing your prompt is a dollar # sign and that doesn't ever appear in # traceroute output... last if ($data =~ /\$/); } print "\n"; $t->print("exit"); $t->close;
Good luck...

In reply to Re: how do I read from a socket one byte at a time? by kschwab
in thread how do I read from a socket one byte at a time? by reyjrar

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.