2

I want to create a cross platform solution for providing access to the input, error and output streams of a Process in Java.

Basically, 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?

3
  • What problem did you get with pasting, backspace etc.? I would think that the component you are redirecting the key events too should handle all events. So if there are things not happening as you wish I would look if you are using the right component. Commented Feb 10, 2011 at 12:36
  • When someone pastes something, the component receives a ctrl+V event, but a lot more than that is added to the text area. This too, I could detect, but when do I send it to the input stream? Right away? But what if someone pastes something, presses backspace a few times and then return? Commented Feb 10, 2011 at 12:49
  • Are you using a buffered stream? I'd use a buffered streams and send immediately at each return key. Buffered-ness should take care of backspaces and arrow keys and all that Commented Feb 10, 2011 at 12:59

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

I think his question is about a command-line application :) So no buttons and areas will help I guess.
@Simeon "Basically, what I want to create is a text area that displays the Process' output", this is what made me think it was a GUI application, but if not, fair enough.
Seems (from reading the comments) I'm wrong and it actually has a GUI ... I should have read the question more carefully. Apologies :)
0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.