Shell commands are blocking -- work around?

Sivakatirswami katir at hindu.org
Mon Nov 13 05:17:06 EST 2006


John: your idea of using a cron is excellent I would probably just have
Revolution write directly to cron (as I have this already set up...)
and pass the parameter along with it. Though i think I will use this for
other tasks, not this one. But that's definitely a keeper.

Sarah: I'll try using your method first, why don't
you use "send in 1 second until the file is not empty" or something like
that, instead of a repeat loop with wait?

BTW: from man sh, "REDIRECTION" Section
The mysterious part.. still archane, but there's a touch of light here.
and lots of other stuff in man sh, if you have the stomach for bash.

=========
Note  that  the order of redirections is significant.  For example, the
        command
               ls > dirlist 2>&1
        directs both standard output and standard error to  the  file
dirlist,
        while the command

   ls 2>&1 > dirlist

        directs  only the standard output to file dirlist, because the
standard
        error was duplicated as standard output before the standard
output  was
        redirected to dirlist.
=========

Sivakatirswami


Sarah Reichelt wrote:
> On 11/11/06, Sivakatirswami <katir at hindu.org> wrote:
>> Some on our team are *nix nerds and if I need a powerdrill to add
>> to my tool box they are, being long time masters of the unix
>> patchwork quilt method of micro programs and  pipes...  more than
>> happy to give me a little bash script. OK so, my cmd line skills
>> are slowly improving and I can install these widgets in
>> 
>> /usr/local/bin/some_cool_tool.sh  # on my OSX box, G4 Powerbook
>> 
>> e.g.
>> 
>> SEARCH_PATTERN=$1 locate index.shtml | while read INDEX_FILE; do 
>> fgrep -H -i "$SEARCH_PATTERN" $INDEX_FILE done | more exit 0
>> 
>> (wow, that is soooo concise!)
>> 
>> and  then in Revolution set up a button:
>> 
>> on mouseUp put empty into fld "results" set the shellCommand to
>> "/bin/sh" put "/usr/local/bin/web_content_search.sh" & quote & fld
>> "findString" & quote into tShellCmd put shell (tShellcmd) into fld
>> "results" end mouseUp
>> 
>> It all works, is very "sweet" And it is a  *lot* faster than using 
>> transcript for the same job. *but* Only problem is: it is
>> blocking... and this is documented behavior:
>> 
> 
> Here is my way around this problem. The example below is for a "ping"
>  command, but I'm sure you can adapt it to your stuff.
> 
> As you can see, I direct the output of the shell command to a 
> temporary text file. The second part of the shell command containing 
> the "2>&1 &" is the relevant section. I don't understand it but it 
> works :-) The rest of the script just loops around checking to see if
>  there is anything in this file and then parsing the result. Since it
>  uses wait with messages, it is non-blocking.
> 
> HTH, Sarah
> 
> function checkPing pIP put specialFolderPath("Desktop") & "/ping.txt"
> into tFileName if there is a file tFileName then delete file
> tFileName
> 
> put "ping -c1 -n "  & pIP into tShellCmd put " > " & tFileName & "
> 2>&1 &" after tShellCmd get shell(tShellCmd)
> 
> put 0 into timeCheck repeat 50 times add 1 to timeCheck wait 1 tick
> with messages if there is a file tFileName then put URL ("file:" &
> tFileName) into tRes if tRes is empty then next repeat  -- file
> created but no result yet
> 
> put wordOffset("loss", tRes) into tWord if tWord = 0 then next repeat
> -- file created but result not complete
> 
> -- if there is a file tFileName then delete file tFileName put word
> tWord-2 of tRes into tPercent if tPercent = "0%" then return true 
> else return false end if end repeat
> 
> if there is a file tFileName then delete file tFileName return false 
> end checkPing _______________________________________________ 
> use-revolution mailing list use-revolution at lists.runrev.com Please
> visit this url to subscribe, unsubscribe and manage your subscription
> preferences: http://lists.runrev.com/mailman/listinfo/use-revolution
> 




More information about the use-livecode mailing list