Skip to content
This repository has been archived by the owner on Jun 21, 2018. It is now read-only.

Commit

Permalink
Bugfix/script (#27)
Browse files Browse the repository at this point in the history
* Fixed bug with script reading from stdin
  • Loading branch information
melnikk authored and AlexAkulov committed Jan 19, 2017
1 parent e126e2f commit 3f0ad1c
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions script/script.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package script

import (
"bytes"
"encoding/json"
"fmt"
"io"
"os"
"os/exec"
"strings"
Expand Down Expand Up @@ -73,13 +73,15 @@ func (sender *Sender) SendEvents(events notifier.EventsData, contact notifier.Co
}

c := exec.Command(scriptFile, args[1:]...)
stdin, _ := c.StdinPipe()
io.WriteString(stdin, string(scriptJSON))
io.WriteString(stdin, "\n")
stdin.Close()
scriptOutput, err := c.CombinedOutput()
var scriptOutput bytes.Buffer
c.Stdin = strings.NewReader(string(scriptJSON))
c.Stdout = &scriptOutput
log.Debugf("Executing script: %s", scriptFile)
err = c.Run()
log.Debugf("Finished executing: %s", scriptFile)

if err != nil {
return fmt.Errorf("Failed exec [%s] Error [%s] Output: [%s]", sender.Exec, err.Error(), string(scriptOutput))
return fmt.Errorf("Failed exec [%s] Error [%s] Output: [%s]", sender.Exec, err.Error(), scriptOutput.String())
}
return nil
}

0 comments on commit 3f0ad1c

Please sign in to comment.