Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Can't display last line with IO::Socket::INET

by swkronenfeld (Hermit)
on Jan 20, 2005 at 06:24 UTC ( #423612=perlquestion: print w/replies, xml ) Need Help??

swkronenfeld has asked for the wisdom of the Perl Monks concerning the following question:

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: 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.

Replies are listed 'Best First'.
Re: Can't display last line with IO::Socket::INET (read)
by tye (Sage) on Jan 20, 2005 at 14:21 UTC
Re: Can't display last line with IO::Socket::INET
by dave_the_m (Monsignor) on Jan 20, 2005 at 14:16 UTC
    You are using  <> to read complete lines from a socket. If you only want to read partial lines, then then you'll need a different approach, most likely involving sysread()


Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://423612]
Approved by BrowserUk
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (3)
As of 2023-10-03 07:17 GMT
Find Nodes?
    Voting Booth?

    No recent polls found