User Tools

Site Tools


dictionary:more:asyncshell

Do Async Shell Script

Like Apples “Do Shell Script” command but performed asynchronously. You can receive the result of the script and any output in the callback handler. That can be in a global script, a units ON script or an Interface script. The callback will have 3 parameters and be of the form: on nameOfCallback( resultCode, output, executionTimeMS) the result code will be 0 for successful completion, -256 if a timeout has occurred and the return code of the command if any other error occurred. The problem with the applescript do shell script command is that the entire program is blocked while you’re running it which is not acceptable for home automation. This allows you to run shell commands and not worry about how long they might take to complete.

Usage:

do async shell script [text] the command you wish to run in a shell including any switches or other parameters.

callback script [text: optional] if you wish the callback to happen in a different script than the one you started the call from you must specify the name of the of the global script, unit or interface here. Otherwise the callback will happen in the same script you started the shell from.

callback handler [text] the name of the handler into which the result of the shell command and any output will be sent.

timeout [integer: optional] number of seconds to allow the shell script to run before forcing it to quit. The default is 30 seconds.

callback unit [text: optional] if you wish the callback to happen in a different units ON script pass the name of the unit here.

callback interface [text: optional] if you wish the callback to happen in a different interfaces script pass the name of the interface here.

shell type [text: optional] the shell to run the command in. Default is “bash” but if necessary you could specify “bourne” or any other shell available on the machine. Make sure the shell is available or the script will not run.

Examples:

  do async shell script “ping -c 3 www.apple.com” callback handler “pingComplete"
  
  on pingComplete( resultCode, output, executionTimeMS)
   if resultCode is 0 then
     write log “apple.com is available"
   else
     write log “apple.com is NOT available!” color red
   end if
  end pingComplete

Notes:

  • Added to XTension in version 9.3 on 6/2/2017
dictionary/more/asyncshell.txt · Last modified: 2023/02/13 14:52 by 127.0.0.1