0

I have a Hubot instance running on an IRC. Inside my scripts directory, I have several coffeescripts linking to external python scripts. My issue is that I have data that should print out before other data within the external scripts such as "Processing request. Please wait..." etc and Hubot waits for the entire script to completely finish executing and dumps the output the IRC at once.

How do I modify my coffeescripts to send over output from an external script as it is received?

coffeescript example:

# 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])

Thanks!

Ryan Peters
  • 115
  • 1
  • 11

2 Answers2

1

I had this same problem. The solution was to pass the "-u" flag to Python when calling the Python script from Hubot.

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

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

Community
  • 1
  • 1
0

Could it be because of bad identation in your example script?

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

Should be:

output.stdout.on 'data', (data) ->
    msg.send data.toString()
Spajus
  • 7,356
  • 2
  • 25
  • 26
  • Sorry, that was an error on my part when copying and pasting. The coffeescript is indented correctly. I have updated the code above. – Ryan Peters Mar 03 '14 at 18:55