如何与Hubot运行asynchronousRuby脚本?

我想把我的一个Ruby脚本提供给不是开发人员的团队成员(读“不愿意设置和维护Ruby环境”)。

我们也在团队中使用Hubot 。

到现在为止,我确信你已经猜到了我的问题:“我怎么能写一个可以调用我的Ruby脚本的Hubot脚本(CoffeeScript,也就是JS)?

ps:我的脚本需要一段时间才能完成,如果你们有一个关于如何让我的hubot给出一个快速反馈(“我听到你,我要运行你的脚本”)的想法,然后通知我,当脚本是完成(“你的脚本成功完成”),这将是真棒。

我相信,你现在可能已经明白了,但是由于这个问题帮助了我,我可以从肖恩的答案中解脱出来,完成这个难题。

module.exports = (robot) -> robot.respond /your regex/i, (msg) -> cp = require "child_process" cp.exec "./path/from/root/to/ruby script", (error, stdout, stderr) -> if error msg.send "Sorry I encounted this error \n" + stderr else msg.send "Done. The output: \n" + stdout 

我希望这有帮助。

你能用exec来运行你的脚本吗? 就像是:

 module.exports = (robot) -> robot.hear /run my command/i, (msg) -> exec "cd /path/to/ruby/script && ruby yourscript.rb" msg.send "i heard you, i'm gonna run your script." 

希望这可以让你走在正确的道路上。 我不知道什么样的钩子,你需要等待,直到执行完成成功通知脚本是否正确运行,但希望谷歌可以帮助:)