[Tutor] Getting process output in real time

Neil Hodge hodge3@llnl.gov
Thu May 1 16:23:01 2003


Jeff:

Jeff Shannon wrote:
> Neil Hodge wrote:
> 
> 
> You may be able to use read() on your pipe object to, in essence, poll 
> for new data.  Perhaps easiest would be to fire off your CLI program in 
> a secondary thread, and use read(1) to grab individual bytes of output 
> from it and then post those back to your main (GUI) thread.

This sounds about right.  So, within the CLI thread, I am thinking 
something like the following (more or less):

[open pipe, etc.]
while 1:
     string = None
     while 1:
         c = read(fd, 1)
         string = string + c
	if c = os.linesep:
             break
     [assign string representing whole line to
     trans-thread variable for action by other thread]
     [check break condition for outer loop here]
[close pipe]

Seem reasonable?

Neil