Satimage Previous | Next
Polling a UNIX executable
Home Documentation Smile Computing Working with external codes Using a UNIX executable Polling a UNIX executable  
If the execution of your code lasts more than a few seconds you may want to have it run in the background.
  • To have a code run in the background, append & to the command, and pipe the result and the errors to a file with &>.
    do shell script will return immediately, while the command proceeds.
    -- assume f_in is the POSIX path to some data file with extension .ctl
    set f_out to change ".ctl$" into ".out" in f_in with regexp
    set sh_scpt to "/sw/bin/spl " & f_in & " &> " & f_out & " &"
    do shell script sh_scpt
  • To have a code run in the background without piping the result to a file, you must pipe the result to /dev/null:
    set sh_scpt to "/sw/bin/spl " & f_in & " &> /dev/null &"
    do shell script sh_scpt
  • To have your script wait until completion of the command, poll the processes for it in a loop, and insert the smilepause command to keep the application responsive: while your script waits you can use Smile normally. See the example below where we run a fictitious executable named spl.
    repeat
        if "/sw/bin/spl" is not in (do shell script "ps -xww") then exit repeat
        smilepause 0.01
    end repeat
    set s to read POSIX file f_out
  • To terminate the execution of your script while it is executing smilepause in a loop, press the esc key. This will trigger an error number -128 ("User canceled") which, unless trapped with try [...] end try, will stop the script.
Version française
Copyright ©2008 Paris, Satimage