Node.js hubot execute commands on the server

天大地大妈咪最大 提交于 2019-12-07 17:11:56

问题


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?


回答1:


process.chdir('/var/folder')

is what I was looking for.




回答2:


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



来源:https://stackoverflow.com/questions/10625846/node-js-hubot-execute-commands-on-the-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!