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