I'm designing a console application for a server running RedHat. The end users should be able to run this app with any terminal of their choosing. (For example; Gnome Terminal, Putty SSH/ Telnet, MS Telnet Client and others).
In most terminal applications there's nothing wrong, however when I launch my program from a MS telnet session I notice my special inputs for System.in
and System.console()
get totally messed up. A backspace will write ^H
to the screen and other keys write gibberish as well.
I've hacked at it enough that I can get it to consistently work, but I'm sure what I'm doing is gross:
if (!System.getenv("TERM").equals("xterm"))
{
System.out.println("\nWARNING: The TERM type is now set to xterm\n");
final String[] cmd = { "/bin/sh", "-c", "export TERM=xterm" };
Runtime.getRuntime().exec(cmd);
}
Would there be an issue here for terminals that don't support xterm
? I notice that the Microsoft Telnet client doesn't allow you to set the TERM
type to xterm
before you begin a session. Once the session is started, however, setting TERM=xterm
seems to solve the problem.
How do most console applications go about this issue?