Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing output of a program to a text area in a gui

Status
Not open for further replies.

jeremytaffy

Technical User
Sep 6, 2001
75
US
Im creating a gui with a text area in it. I want to be able to run a program and display the output of the program in the text area instead of the usuall dtterm window. I was originally thinking of piping the ouput of the program to a file and using a stream to bring it in the area, but if there is a way to send the information directly to the textarea I wont need to.

Please let me know how this might be done.
Thanks in advance.
 
Hi,

I'm doing this in following way:

pro = rt.exec(cmd);
System.out.println("pro : " + pro.toString());
BufferedReader input = new BufferedReader (new InputStreamReader(pro.getInputStream()));
while ((line = input.readLine()) != null) {
lstTextArea.append(line+NEW_LINE);
}
input.close();

This is nice to geta feeling of output line by line,. If you have larger text user following read method:

while ( (chread
= inp.read(inBuffer, 0, inBuffer.length)) != -1) {
srcTextArea.append(
line.copyValueOf(inBuffer, 0, chread));
};
variate size of char array "chread" to setup size of buffer.

Best Regards,
Miso
 
Yes that is the perfect way.

You might also think about putting the exec and the
subsequent text appending on a seperate thread so that
the rest of the ui remains responsive while the process
executes. An example would be opening a socket to a
server running on another machine and sending a request
then putting the server response into a text area of
the client. If the connection is slow or the server
is backed up or the process is long on the server side
the client ui will remain unresponsive while waiting.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top