in reply to Re^2: Output telnet session to file
in thread Output telnet session to file

Here's a brief example:
#!/usr/bin/perl use strict; use warnings; use Net::Telnet; my $t = Net::Telnet->new( Timeout => 10, Port => 80 ); $t->open('www.google.com'); $t->print('GET /'); my $line = 0; while (my $o = $t->getline()) { print ++$line . '. ' .$o; }
Instead of port 80, you'd use port 6666. Instead of www.google.com, you'd use the real server. Instead of printing GET /, you'd do whatever starts the flow of information (which may be nothing - if so, remove that line). Instead of printing the line inside the while loop to STDOUT (the default), you'd print to a filehandle that you opened prior to the while loop, and you'd flush the filehandle after each write. So, something like this, which, unlike the above, is untested:
#!/usr/bin/perl use strict; use warnings; use Net::Telnet; my $t = Net::Telnet->new( Timeout => 10, Port => 6666 ); $t->open('mydataserver') or die "Can't connect to mydataserver: $!"; open my $fh, '>', '/tmp/file' or die "Can't write to /tmp/file: $!"; $fh->autoflush(1); while (my $o = $t->getline()) { print $fh $o; # or $fh->print($o); } close $fh;