简体   繁体   中英

Node.js hubot execute commands on the server

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?

process.chdir('/var/folder')

是我在寻找的。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM