shell vs. process

Sarah Reichelt sarah.reichelt at gmail.com
Wed Oct 4 20:05:47 CDT 2006


> In Revolution, which function is better for calling a long-running
> external process and reading data from the process in a non-blocking
> format, for instance, streaming the output from tcpdump into a text
> display?
>
> Looking at the docs, it appears that "process" is what I want, but I saw
> something that says that "open process" on OS X is only useful for
> launching applications...not launching background command-line processes
> and reading their output to stdout as one would expect to do on a
> Unix-style platform. Since I am targeting OS X, I need to know how
> others handle this.
>

Getting to this thread a bit late, but here is how I do a ping without
blocking anything else. It is very quick if the ping is successful,
but it's the failure delay that has to be allowed for.

**********
on mouseUp
    put checkPing("www.garbageaddress.com")
end mouseUp

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
**********

As you can see, I redirect the output of a shell command to a text
file, then have a loop that keeps checking until the file is there.
Because the loop uses "wait with messages", it doesn't stop anything
else from happening. After that, I analyze the text in the file to see
how successful the ping was, before deleting the file.

Depending on how long you would expect the command to take, you can
adjust the wait time inside the loop and the number of times the loop
happens.

Cheers,
Sarah



More information about the use-livecode mailing list