1

I am working on developing GUI for java programming.

I wish to implement a console (terminal like thing) in my GUI, for compiling and executing the programs created. ( like console window in eclipse ). I went through several tutorials (including stackoverflow).

I got some solutions to redirect the System.out and System.err to TextArea. Okay. I am happy with that.

But when I run a java program, by using these things, I can't give input to the program which is executing.

For example, with my present status, I can see::

Enter a Number: in TextArea but can't input to the program.

To complete the function of the console I could be able to give input to the program in execution too..!! But I dont know how to do that..!! I am in big trouble.

Ajoy
  • 1,838
  • 3
  • 30
  • 57
AKA
  • 5,479
  • 4
  • 22
  • 36
  • Give us some example code that you have. It is definitely possible, since Netbeans and Eclipse both provide such output windows. – RudolphEst Mar 06 '13 at 09:56
  • [this](http://stackoverflow.com/questions/342990/create-java-console-inside-the-panel) link is having that program. – AKA Mar 07 '13 at 05:08

2 Answers2

1

Assumption is that you are working with a Process. To get a Process, start your programs with ProcessBuilder. The Process gives access to the process's in/out streams. You can then use those streams in whatever way you need. If you want your process to interact with system in/out, then you will need to copy them to/from the corresponding System streams.

See this question/answer for an example:

and the follow-up:

Also, see the new ProcessBuilder.inheritIO() method that was added in Java 7.

Community
  • 1
  • 1
kaliatech
  • 17,579
  • 5
  • 72
  • 84
0

this might help you http://www.dreamincode.net/forums/topic/273874-redirect-systemin-to-jtextarea/

this guy has directed stdin to jtextarea..