Skip to Main Content

Java HotSpot Virtual Machine

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

support command history for Java program with CLI

843811Apr 24 2004 — edited Apr 26 2004
I 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.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 24 2004
Added on Apr 24 2004
1 comment
382 views