title: Capture stdout from command exec in real time
body: <p>I'm currently working on a chat bot that will perform commands. One thing I want it to do is be able to run scripts and output the stdout of the script into the chat.</p>
  
  <p>The issue I am having is that the function collects all of the stdout of the script and returns them all at the end, I'd like to try and modify it to write in real time and have had issues doing so. </p>
  
  <p>What I think the issue might involve is that there is only one way for it to return text to the chat channel and that is via the return function of reboot. However I'd like to iterate over the exec command and output that if possible.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>func reboot(command *bot.Cmd) (string, error) {
      n := command.Args[0]
      // this return is what all gets sent into chat channel
      return runcommand(n), nil
    }
  
  
  func runcommand(server string) string {
      cmd := exec.Command("/bin/bash", "-c", "python test.py %s", server)
      cmdOutput := &amp;bytes.Buffer{}
      cmd.Stdout = cmdOutput
      err := cmd.Run()
      if err !=nil {
          os.Stderr.WriteString(err.Error())
      }
          return fmt.Sprintf(string(cmdOutput.Bytes()))
  }
  </code></pre>