How do you pass arguments to binary workers? #258

Open
justengland opened this Issue Nov 23, 2012 · 2 comments

Comments

Projects
None yet
3 participants

It took me a little while to figure it out how to pass payload arguments to binary workers, I am still a shell scripting noob. I got it working phantomjs example, hopefully this will save some people some time.

When I use the CLI tool to run my worker -
$ iron_worker run phantom --payload '{test:"me"}'

I was unable to access the payload from the phantom script, I had to update bash script in the worker.

run.sh
payloadFound="false"
value=""
for var in "$@"
do
if [ $payloadFound = "true" ]
then
#echo "readfile"
value=$(cat $var)
payloadFound="false"
fi

if [ $var = "-payload" ]
then
    #echo "found"
    payloadFound="true"
fi      

done

phantomjs-1.6.0-linux-x86_64-dynamic/bin/phantomjs nearme.js pizza "$value"

Contributor

paddycarver commented Nov 27, 2012

Hey @justengland, thanks for pointing that out. We're currently working on an overhaul of the worker documentation that is better about making all the information cross-language, so we'll be sure to include this.

thadk commented Jul 18, 2013

This is still quite difficult to discover. Thanks for this post.

If you would like the payload to resolve as multiple arguments to your script rather than all as one, remove the quotes around "$value".

payloadFound="false"
value=""
for var in "$@"
do
  if [ $payloadFound = "true" ]
  then
    #echo "readfile"
    value=$(cat $var)
    payloadFound="false"
  fi

  if [ $var = "-payload" ]
  then
    #echo "found"
    payloadFound="true"
  fi
done
phantomjs-1.6.0-linux-x86_64-dynamic/bin/phantomjs nearme.js pizza $value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment