Arieh's Weblog

     
 
CLIs in Java - Totally doable

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 arieh @ 07:52 AM MST [ Comments [1] ]
 
 
 
 
Comments:

Thanks for the tip. The telnetD project certainly looks interesting. From what I've read it will allow me to set up a Java app that I can then telnet into. What seems to still be missing is the ability to put the invoking terminal in raw mode. What I'd like to do for instance is to write a java clone of 'bash'. I'd like to be able to do something like this: % java -jar JavaBash.jar; JavaBash> echo hello world; hello world JavaBash> Where JavaBash allows cmd line editing. With this telnetD package, unless I am wrong, you would have to do something like this: % java -jar JavaBash.jar -port 2222& % telnet localhost 2222; JavaBash> echo Hello world; It's not quite the same.

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

Post a Comment:

Comments are closed for this entry.
 
« December 2009
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
  
       
Today

[RSS Newsfeed]

Valid XHTML or CSS?

[This is a Roller site]
Theme by Rowell Sotto.
 
© Arieh's Weblog