Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-04-19 19:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found