1

我想让我的一个 Ruby 脚本可供我的非开发人员使用(阅读“不愿设置和维护 Ruby 环境”)。

我们还在团队中使用Hubot

到现在,我相信你已经猜到我的问题了:“我怎样才能编写一个能调用我的 Ruby 脚本的 Hubot 脚本(CoffeeScript,即 JS)?”

ps:我的脚本需要一段时间才能完成,如果你们知道如何让我的 hubot 给出快速反馈(“我听到了,我要运行你的脚本”),然后在脚本完成时通知我完成(“你的脚本成功完成”),它会很棒。

4

2 回答 2

2

你能用它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."

希望这能让你走上正确的道路。我不确定你需要放入什么样的钩子让它等到 exec 成功完成后通知脚本是否正确运行但希望谷歌可以帮助:)

于 2012-12-10T19:29:48.670 回答
2

我敢肯定,您现在可能已经弄清楚了,但是由于这个问题对我有所帮助,我可以摆脱肖恩的回答并完成难题。

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

我希望这有帮助。

于 2013-07-18T21:51:13.363 回答