Command-line interface in Java
I want to create a cross platform solution for providing access to the input, error and output streams of a Process in Java.
Basi开发者_运维知识库cally, what I want to create is a text area that displays the Process' output and error streams, and allows you to supply data to the input stream. In other words, pretty much what Eclipse is already providing with its Console when you run an application.
Now, a basic implementation of this was easy, I simply send all key presses to the input stream. But, of course, I ran into trouble with pasting, backspace and arrow keys, handling ctrl-C and so on.
It seems I should wait before sending data to the Process' input stream. But wait for what? Should I send all entered (and pasted) text at each return key? Or after an interval? What about ctrl-C, ctrl-X and so on. Do I send arrow key movement to the input stream?
The easiest and most user-friendly solution is to have a "Send" button which sends the entire contents of the text area and clears it. Think instant messenger apps or SO comment editor.
You should not wait for anything, simply send - but send in a separate Thread, not your GUI-Event-thread, so the latter one does not block.
For handling the special characters, look what you would get when these signs are entered in a text console.
精彩评论