How to implement a command history on a telnet client? (up/down arrows) How to implement a command history on a telnet client? (up/down arrows) linux linux

How to implement a command history on a telnet client? (up/down arrows)


This isn't a server issue. Just use rlwrap with your telnet client. It gives you readline with no programming.

$ rlwrap telnet server port

(I actually use nc instead of telnet since it is easier to use and is more robust.)


use socat:

socat readline,history=$HOME/.telnet_history TCP:host:23


I'm assuming this is a service you have written in Perl, based on your tags.

You can use the Term::ReadLine module from CPAN to do what you want. From the CPAN website, here's a basic example:

use Term::ReadLine;    my $term = Term::ReadLine->new('My Management Service');    my $prompt = "Enter your management command: ";    my $OUT = $term->OUT || \*STDOUT;    while ( defined ($_ = $term->readline($prompt)) ) {        my $res = eval($_);        warn $@ if $@;        print $OUT $res, "\n" unless $@;        $term->addhistory($_) if /\S/;    }