I had been waiting for a post like this to expose my own biases with regards to CLIs and Java.
Paul states In Java, it is not possible to perform raw console I/O, only line buffered I/O is possible.
Well, I would begin by stating that the above is quite inaccurate. As a matter of fact, I have implemented, and delivered within the Sun StorEdge Configuration Service such Java-written CLI.
How it was done
The Java program exposes a live interpreter that can be accessible from a telnet session (if so configured), as well as from an ssh session. In essence allowing the users of the application to rely on a fully functional (for both one-shot, scripted, and interactive) embedded shell that is portable and does not rely on any of the hosts' shells.
The CLI provides for sufficient tty capabilities (albeit limited to only 4 types of terminal definitions), including implementation of raw character-at-a-time I/O, which allows to implement features like up-arrow/down-arrow for command line recalls, noecho on password prompting, and many of the features one would expect in a shell accessed via telnet or ssh.
Apart from the "virtual tty" that it supports, the implemented shell also provides for command line history recall, environment variables, etc.
Technologies to Rely on
The implementation takes advantage of the Java Telnet Daemon project.Another possible implementation can be found within the Jakarta Commons-Net project. However, I did not use it since Daniel Savarese had not made it available under the Apache license at the time.
Conclusion
My experience has shown that what was originally claimed as undoable, is in fact, very doable. In fact because of that feasibility, I argue that embeddability of a functional shell in an application provides the developer of the application with a good measure of independence, and allows to treat the CLI as just another public interface.The potential hosting of the CLI within the application also reduces the complexity that would have been introduced if they (the CLI and the application) were implemented as different processes.

Posted by Paul on June 16, 2004 at 08:44 AM MST #