In Neal Stephensen's 'In the Beginning ... Was the Command Line' , Neal argues that the command-line interface "opens a much more direct and explicit channel from user to machine than the GUI". I agree, for most tasks, I find that a 'bash' shell, a text editor, and the suite of Unix commands is the most efficient set of tools. But ... don't try to write a command shell in Java!

In Java, it is not possible to perform raw console I/O, only line buffered I/O is possible. The user has to hit [return] before your app sees what the user typed. This means that interactive command-line editing, password input (where the characters typed are not echoed) or curses style apps are not possible in Java. Without this capability it is impossible to write good interactive text apps. You could not write bash in Java, you could not write a non-GUI vi or emacs .

Bug 4050435 "Improved interactive console I/O (password prompting, line editing)" is number 11 on the list of Top RFEs at the Java Bug Parade. This RFE is to provide an API to give Java the ability to put the console in raw mode, to allow for character by character input and output to the terminal. It seems like simple, almost trivial functionality to add to the Java platform, and it would allow the writing of a whole class of applications. However, given that the RFE has been outstanding for Seven Years , it is unlikely that we'll be seeing a Java command line in the near future. But you can help. This RFE only needs about 25 more votes to move it into the top 10 RFEs. If you think Java console apps are important, add your vote to have this RFE fixed. Seven years is a long time to wait for such an important thing.

Update - 12 ours later only 14 votes more to go!

Comments:

Just voted! :-)

Posted by Sitchai on June 16, 2004 at 09:09 AM EDT #

It looks like 6 folks have voted already. 10 more votes and we'll be in the top 10.

Posted by Paul on June 16, 2004 at 09:44 AM EDT #

I use the command line quite a bit. But it's disingenuous to laud the command line as "a much more direct and explicit channel from user to machine." The same can be said for assembly language, or even machine language. "Direct and explicit" is a DISadvantage for most everyday work; you don't WANT to have to fuss over irrelevant details. And BTW, it's not Java that requires that you hit the enter key, it's your operating system.

Posted by Doug on June 16, 2004 at 12:57 PM EDT #

You say that "The user has to hit [return] before your app sees what the user typed." Well this is not really true as you can wrap System.in within an InputStreamReader and read one (or more) character at a time and have the program react accordingly to what the user types in. In a recent blog (http://radio.javaranch.com/channel/val/2004/06/09/1086777039000.html), I use this technique for asking the user what he wants to do. I'm not sure whether this is the goal you are aiming at. Please don't hesitate to comment on that. Thanks :)

Posted by Val on June 17, 2004 at 02:25 AM EDT #

Val: Thanks for the comment. One can indeed read a character at a time, however, no matter what you do, the characters are buffered. If your app has a loop where it is reading a single character from System.in, the loop will block in during the first read waiting for the user to input a character. The user can type in characters all day, but this read will not return until the user hits the [return] key. Once the [return] is hit, the read will indeed return the first character typed (and subsequent reads will return the rest). I would like to be able to do two things: (1) Perform single character-at-a-time input from System.in, (2) Disable the automatic echoing of characters as they are typed. (1) is necessary to allow any sort of command line editing (up arrow to get to previous commands in your command history for instance). (2) is necessary for writing things like password getting routines that echo '*****' when someone is typing their password.

Posted by Paul on June 17, 2004 at 06:11 AM EDT #

Got it Paul :) Thanks for the info... By the way, did you like Neal's book? I have it on my shelf (as well as all his books), but I can't find the courage (or time?) to get my technical ones down :\

Posted by Val on June 17, 2004 at 09:42 AM EDT #

Val - I did like Neal's book (essay really), it was a perfect book for a plane ride: a 2 hour read, thought provoking, and compact... unlike some of Neal's fiction such as the Cryptonomicon that requires its own carry-on bag.

Posted by Paul on June 18, 2004 at 07:20 AM EDT #

Post a Comment:
Comments are closed for this entry.

This blog copyright 2010 by plamere