This version is out of date, covering development from v4.6.0 to v4.7.1. It is maintained here only for inbound reference links from elsewhere.
Jump to the current version of aTbRef.
|A Tinderbox Reference File : Actions & Rules : Operators : Action Operator Scope : Item-based operators : runCommand(commandLine[,inputs])||aTbRef Site Map|
|Operator Type:||Data manipulation|
|Operator Scope of Action:||Item|
The operator, runCommand(), lets rules and actions use the command line.
passes command to the C shell. The new process receives input, if any, as its standard input; the process's standard output is returned as the result of calling runCommand.
Example, if a note called "Jane Doe" is dropped on a container with this OnAdd action:
$MyResult = runCommand("sendmail -f "+$Email+" "+$Email(parent), "Subject:"+$Name+"\nHello\n.")
This assumes both dropped and container notes have a valid email address in Email. If so, Jane Doe will get an email with subject line "Jane Doe" and body text "Hello"; the email will be from the dropped note's $Email address and to the container's $Email address. User attribute 'MyResult' will receive any message back from standard output.
From v4.6, this operator does not require a left-side to the expression where the result of the command line is not needed by Tinderbox. Thus:
runCommand("sendmail -f "+$Email+" "+$Email(parent), "Subject:"+$Name+"\nHello\n.")
In this latter case there is no way of knowing if the command executed successfully.
To use external commands like above you may need to check the encoding of the strings you extract from your TBX attributes. Don't forget to allow for characters like spaces/quotes/apostrophes in attribute values; these will invariably need escaping for safe use in a command line using operators like urlEncode():
$MyResult=runCommand("/usr/bin/curl -d 'status="+urlEncode($Name)+"' -u myusername:mypassword http://twitter.com/statuses/update.atom");
In the above, if the value of $Name were "Mark's project", the use of urlEncode() will ensure the string passed to the command line is actually "Mark%27s%20project".
Exactly where you do/don't need to encode attribute values will depend on the syntax of the particular operation you are performing.
|Up: Item-based operators|
|Previous: round(argument)||Next: saturation(color)|
Licensed under Creative Commons Attribution-Noncommercial-Share Alike 3.0 License
[See aTbRef CC licence Attribution/Waiver info info]