support command history for Java program with CLI
843811Apr 24 2004 — edited Apr 26 2004I am writing a small Java program which has a Command Line Interface (CLI). The program looks like below:
LineNumberReader in = new LineNumberReader(new InputStreamReader(System.in));
while (true) {
printPrompt();
line = in.readLine();
if (line == null || "quit".equals(line)) {
break;
}
executeCommand(line);
}
Running under Windows 2000 and XP, my CLI supports the command history. The user can use the up/down arrow key to retrieve previous commands. Under Windows NT or Windows 9x, similar functions are supported if the DosKey program is installed in the command.exe process which starts JVM.
However, these functions are not supported if the program is running in Unix or Solaris. I would like my program support the command history like the bash shell. I also tried the following script file:
#! /bin/bash
java <my program>
But it did not work.
Anyone who has this experience please help me.
Many thanks.