本文介绍了Node.js hubot在服务器上执行命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用hubot在服务器上执行命令。
此示例适用于我:
robot.respond /(cmd)/ i,(msg)
doing = spawn'ls',['-la']
doing.stdout.on'data',(data) - >
msg.send data.toString()
但是,我需要更改文件夹我执行我想要执行的命令。
我想让hubot运行:
cd / var / folder&& some-command
但是从hubot脚本更改文件夹不起作用。
执行的命令有很多文件根据它驻留的文件夹加载,所以似乎我必须去这个文件夹。
如何让hubot从特定路径执行命令?
解决方案
.chdir('/ var / folder')
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')
is what I was looking for.
这篇关于Node.js hubot在服务器上执行命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!