Javascript – Node.js hubot executes commands on the server

Node.js hubot executes commands on the server… here is a solution to the problem.

Node.js hubot executes commands on the server

I’m trying to execute commands on the server using hubot.
This example worked for me :

  robot.respond /(cmd)/i, (msg) ->
    doing = spawn 'ls', ['-la']
    doing.stdout.on 'data', (data) ->
      msg.send data.toString()

However, I need to change the folder before executing the command I want to execute.
What I want Hubot to run is:

cd /var/folder && some-command

But changing the folder from the hubot script doesn’t work.

The command executed loads a lot of files depending on the folder it is in, so it looks like I have to go to this folder.

How do I get hubot to execute commands from a specific path?

Solution

process.chdir('/var/folder')

Exactly what I was looking for. p>

Related Problems and Solutions