Arieh's Weblog

     
 
CLIs in Java - raw I/O - redux

Paul states:

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.

The solution, as I implemented it, was to create a 'tunnel' client, that would be responsible to set the terminal in raw I/O mode. Here is one example (not the same that I used in my previous implementation) to have a local client that can talk to the shell program that would be created.

So, yes, Java does not support it natively, but workarounds are available until they are available.

PS: A possible kludge could be for your Java jar to fork a Thread to Runtime.exec() a telnet invocation to localhost on an ephemeral port on which the other Thread (the Shell) will be listening.

Posted by arieh @ 06:38 AM MST [ Comments [2] ]
 
 
 
 
Comments:

Thanks for the follow-up. I'm glad to see that other people have thought of creative solutions to this problem. I shall take a look at telnetD the next time I want to embed a shell in an application. Indeed there are work arounds, I've seen some libraries that rely on some JNI-invoked native code to do the raw I/O. Your tunnel client seems like it would work on most-unixes. However, trying to get a solution like this or the JNI workaround to work on Solaris, Linux, WIN32, Mac OS X etc would be a lot of very unpleasant work. I'd be happier if Java support raw console I/O directly.

Posted by Paul on June 17, 2004 at 07:51 AM MST #

Lots of cool function available in BeanShell (beanshell.org), including a GUI console, telnet and servlet server modes.

Posted by Maggie Leber on June 17, 2004 at 09:22 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