summaryrefslogtreecommitdiff
path: root/shell.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2019-06-06 09:34:47 -0700
committerJeff Carr <[email protected]>2019-06-06 09:34:47 -0700
commit8e258d67a3c93dbb46734f211e4262ef3b70ab22 (patch)
tree091b4b209214ec6c862f3f6815ee9414cf082d4a /shell.go
parent223938d4bff3fde28c1b8f47986f58ce63ee2f84 (diff)
make a error handling callback function
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'shell.go')
-rw-r--r--shell.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/shell.go b/shell.go
index d1acb89..31494fe 100644
--- a/shell.go
+++ b/shell.go
@@ -16,6 +16,8 @@ import "github.com/svent/go-nbreader"
import log "github.com/sirupsen/logrus"
// import "github.com/wercker/journalhook"
+var callback func(interface{}, int)
+
var shellStdout *os.File
var shellStderr *os.File
@@ -25,6 +27,18 @@ var msecDelay int = 20 // number of milliseconds to delay between reads with no
var bytesBuffer bytes.Buffer
var bytesSplice []byte
+func handleShell(c interface{}, ret int) {
+ log.Println("shell.Run() Returned", ret)
+}
+
+func init() {
+ callback = handleShell
+}
+
+func InitCallback(f func(interface{}, int)) {
+ callback = f
+}
+
func Script(cmds string) int {
// split on new lines (while we are at it, handle stupid windows text files
lines := strings.Split(strings.Replace(cmds, "\r\n", "\n", -1), "\n")
@@ -60,6 +74,8 @@ func SetStderr(newerr *os.File) {
shellStderr = newerr
}
+// NOTE: this might cause problems:
+// always remove the newlines at the end ?
func Run(cmdline string) (int, string, error) {
log.Println("shell.Run() START " + cmdline)
@@ -164,6 +180,11 @@ func Run(cmdline string) (int, string, error) {
// reset the bytesBuffer
bytesBuffer.Reset()
+
+ // NOTE: this might cause problems:
+ // this removes the newlines at the end
+ tmp2 := string(b)
+ tmp2 = strings.TrimSuffix(tmp2, "\n")
log.Println("shell.Run() END ", cmdline)
return 0, string(b), fmt.Errorf("") // nothing to do
}