Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CoffeeScript - Execute bash script with arguments

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

like image 732
eouti Avatar asked Feb 17 '14 13:02

eouti


1 Answers

As explained in the documentation:

http://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options

Spawn take, as second parameter, an array made of your different arguments. It would look like this:

s = spawn './myScript.sh', [url, title]
like image 89
Aurélien Thieriot Avatar answered Sep 22 '22 07:09

Aurélien Thieriot