0

我有一个在 IRC 上运行的 Hubot 实例。在我的脚本目录中,我有几个咖啡脚本链接到外部 python 脚本。我的问题是我的数据应该在外部脚本中的其他数据之前打印出来,例如“处理请求。请稍候......”等,Hubot 等待整个脚本完全完成执行并立即转储 IRC 的输出.

如何修改我的咖啡脚本以在收到外部脚本时发送输出?

咖啡脚本示例:

# Commands:
#   Hubot jira-add-comment <ticket> "comment" - Add given comment to a JIRA ticket

{spawn} = require 'child_process'
module.exports = (robot) ->

addComment = (msg,ticket,comment) -> 
    output = spawn "/path/to/externalscript.py", [ticket,comment]
    output.stdout.on 'data', (data) ->
        msg.send data.toString()

robot.respond /jira-add-comment (\w+-\d+) (.+)$/i, (msg) ->
    addComment(msg,msg.match[1].trim(),msg.match[2])

谢谢!

4

2 回答 2

1

我有同样的问题。解决方案是在从 Hubot 调用 Python 脚本时将“-u”标志传递给 Python。

s = spawn 'python', ['-u', '/your/script/here.py', 'any_other_flags']

https://unix.stackexchange.com/questions/182537/write-python-stdout-to-file-immediately

于 2015-07-14T22:36:44.307 回答
0

可能是因为您的示例脚本中的标识错误?

output.stdout.on 'data', (data) ->
msg.send data.toString()

应该:

output.stdout.on 'data', (data) ->
    msg.send data.toString()
于 2014-02-26T19:24:22.140 回答