3

I am trying to execute a command on the server using hubot. This example works 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 I execute 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 executed command has a lot of files loaded based on the folder it resides in so it seems I have to go to this folder.

How can I make hubot execute a command from a specific path?

2 Answers 2

4
process.chdir('/var/folder')

is what I was looking for.

Sign up to request clarification or add additional context in comments.

1 Comment

if you use the child_process.exec(command[, options], callback) the options object takes a cwd parameter which changes the "Current working directory of the child process"
0

Not familiar with hubot, but have you tried shell command chain something like 'cd /var/folder; some-command'?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.