I have an extremely basic telnet program in perl as follows
#!/s/std/bin/perl -w use strict; use IO::Socket::INET; if(@ARGV != 1) { die("usage: client.pl host:socket\n") } my $sock = new IO::Socket::INET("$ARGV[0]") or die("Couldnt connect: $ +!"); my $pid = fork(); if($pid == 0) { #$|++; while(<$sock>) { print $_; } } else{ while(<STDIN>) { print $sock $_ } } close($sock);
The problem is, the last line of text received from the server is a prompt which doesn't contain a line break. This line doesn't get displayed until after I provide my input. So my output might look something like this...
Connecting to xxx ls** home$ public private somefile ...
The ls is my input, the home$ is the missing prompt, appearing before the file listing.

I thought at first that this was a problem with autoflush, but when I added the above $|++ line to STDOUT (which is what I *think* I'm doing, I also tried STDOUT->autoflush(1);), it didn't fix anything. I attempted to manually print a line break immediately following any output received from the server (which isn't my desired behavior), but that just adds line breaks after every single line, and still doesn't display the last line.

Does anyone have any advice for this problem? I'm not really sure where to go, I tried reading about sockets, but there's a ton of information, and there's nothing regarding this kind of thing in the CPAN info on this module.


In reply to Can't display last line with IO::Socket::INET by swkronenfeld

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.