If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Threaded View

stdout stderr synchronization

Dear users,

i am trying to develop a front end to a linux based program. i am using swing (j2sdk 1.4.2) for this purpose. the gui part of it works fine and i could manage to get the program running on my linux system using getRuntime().exec(). And I would like to pipe the output back to the gui window and display it in a non-editable textarea. The program writes output both to the stdout and stderr streams. i could read both the streams using the getOutputStream() and getErrorStream() methods. and i have no problems getting it back to the gui window. but my problem is synchronization. the program writes to these two output streams, alternately. so, if i read one of the streams completely and go to the other, the output i would endup displaying in my gui window would be out of order, as compared to what i would read, had i run the program on the command line (independent of the gui window). so, is there any way of threading, so that i can read from the standard output streams of the program, in such a way that the output in my gui window conforms with the order it follows on the command line? Precisely, i would like to know how to detect the beginning of a stream, and how to react to minor pauses in the streams.