Shell command doesn't give feedback until done

Brian Yennie briany at qldlearning.com
Thu Jun 2 23:10:38 EDT 2005


OK, since I started us down a dead-end path, here's some goodies that 
DO work.
Create a new stack. Put the handlers below in the stack script.
Now create one large scrolling field.

Now run this in your message box, a lengthy shell task (finding all 
html files in your Applications directory):

## RUN find /Applications/ -name '*.html as an asynchronous task and 
stream the data back
put async_shell("find /Applications/ -name '*.html'") into tProcessID
repeat while async_process_alive(tProcessID)
    put async_shell_get_data(tProcessID) into fld 1
    wait 1 second with messages
end repeat
put async_shell_get_data(tProcessID) into fld 1

It could use a little polishing, but it works! Asynchronous shell tasks 
on MacOS X...!

#######

global _async_shell_counter, _async_shell_map

function async_shell tCmd
   if (_async_shell_counter is empty) then put 1 into 
_async_shell_counter
   else add 1 to _async_shell_counter

   put specialFolderPath("temporary") into tFilePath
   if (last char of tFilePath <> "/") then put "/" after tFilePath
   put ("revTmp"&_async_shell_counter&".out") after tFilePath

   put tCmd&" &> "&tFilePath&" & echo $!" into tCmd

   put shell(tCmd) into tProcessID
   put tFilePath into _async_shell_map[tProcessID]

   return tProcessID
end async_shell

function async_process_alive tProcessID
   put shell(("ps -p"&&tProcessID)) into tProcessList
   return (offset(tProcessID, tProcessList) > 0)
end async_process_alive

function async_shell_get_data tProcessID
   return url ("file:"&_async_shell_map[tProcessID])
end async_shell_get_data

> Ugh. I just tried this and it doesn't work in Rev- although it's the 
> standard way to deal with this sort of task in a terminal.
> I'm guessing that Rev refuses to return until the process is 
> completely terminated- and opens a whole new shell environment every 
> time you call shell(). How rude!
>
> Now picking for a workaround... sorry for the false alarm.
>
>> On 6/2/05 4:23 PM, Brian Yennie wrote:
>>
>>> Agh, sorry- I obviously missed the point of the thread.
>>> Add an ampersand after your command:
>>> get shell("mycommand > mylogfile.log &")
>>> Voila, a "backgrounded" process that returns immediately.
>>
>> Oh cool. I will go try it. I have a use for this. :)
>>
>> -- 
>> Jacqueline Landman Gay         |     jacque at hyperactivesw.com
>> HyperActive Software           |     http://www.hyperactivesw.com
>> _______________________________________________
>> use-revolution mailing list
>> use-revolution at lists.runrev.com
>> http://lists.runrev.com/mailman/listinfo/use-revolution
>>
>>
>
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> http://lists.runrev.com/mailman/listinfo/use-revolution
>
>



More information about the use-livecode mailing list