Read from process

Glen Bojsza gbojsza at gmail.com
Wed Mar 28 21:01:00 EDT 2012


Hi Mike,

Well using your code I get the expected result at the end of the process
but the interim output that I try to capture shows nothing?

So good news - using your method I get the end result and the user is free
to do other things  ; / bad news - I can't show the interim output for
feedback.

If I use the following code I get the opposite effect - user cannot do
anything until the process completes but the interim output updates to the
field.

In both cases the process completes with the final results.

So it has to do with the timing of the send and the reading of the process
(I also tried reading lines and have the same result as reading characters
as shown below)

local nM
on mouseUp
   startProcess
end mouseUp

command startProcess
   put fld dbPathList into nM
   open process nM for update
   set the cRunning of this card to true
   readloop
end startProcess

command readloop
   if the the cRunning of this card then
      read from process nM for 10
      if it is not empty then
         put it & cr after fld mergeOut
         put the number of lines of fld mergeOut * 16 into sPlace
         set the vscroll of fld mergeOut to sPlace
         if it contains "dblink disconnecting" then
            set the cRunning of this card to false
            close process nM
            exit to top
         end if
         send "readloop" to me in 1 tick
      end if
      end if

end readloop

On Wed, Mar 28, 2012 at 5:35 PM, Mike Bonner <bonnmike at gmail.com> wrote:

> Sorry for posting and falling off the earth. A bit sick today but will try
> and give the gist of a send in time loop. This is just off the top of my
> head and as always there are probably better ways to do this (also as I
> mentioned before, not sure which forms of read will block and which won't
> so your mileage may vary depending on need)
>
> command startProcess
> ## code to connect to the process
> open process "myprocess" for update
> ## check for errors opening the process, if no errors then
> set the cRunning of this card to true -- a method to break the loop, set to
> false to stop the loop
>
> readloop -- handler to do the read
> end startProcess
>
> command readloop
> if the the cRunning of this card then
> read from process "myProcess" until empty
> if it is not empty then
> #do whatever you want with the resulting read.
> #if the end line is read, close process set the cRunning of this card to
> false
> end if
> send "readloop" to me in 1 tick
> end if
>
> end readloop
>
>



More information about the use-livecode mailing list