I am playing around with GitHub's Hubot, and I try to execute a bash script inside my robot work.
I succeed executing my script, but cannot get it working if I add some arguments to this script.
{ spawn } = require 'child_process'
s = spawn './myScript.sh' + " url" + " title" <------- doesn't work due to args
s = spawn './myScript.sh' <------- alright without args
s.stdout.on 'data', ( data ) -> console.log "Output: #{ data }"
s.stderr.on 'data', ( data ) -> console.error "Error: #{ data }"
s.on 'close', -> console.log "'s' has finished executing."
How do I pass arguments to my script ?
Thanks for help
spawn "./myScript.sh #{url} #{title}"but that would leave you open to all sorts of unpleasant quoting and injection problems. Never ever use the single argument form ofspawn,system, or similar "launch a shell to do things for me" commands, there's almost always a multi-argument form that bypasses the shell completely. Aurélien's answer is the right way.