-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexecutor.go
46 lines (33 loc) · 844 Bytes
/
executor.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package main
import (
"bufio"
"fmt"
"os/exec"
log "github.com/sirupsen/logrus"
)
const defaultShell = "/bin/bash"
// RunScript runs the script that has been fetched as requested
func (sm *ScriptManager) RunScript(sn string) error {
s := fmt.Sprintf("%s/%s", sm.WorkDir, sn)
log.Debugf("about to run : %s", s)
cmd := exec.Command(defaultShell, s)
cmdReader, err := cmd.StdoutPipe()
if err != nil {
return fmt.Errorf("error creating stdout pipe for '%s' : %s", s, err)
}
scanner := bufio.NewScanner(cmdReader)
go func() {
for scanner.Scan() {
log.Infof("%s | %s", sn, scanner.Text())
}
}()
err = cmd.Start()
if err != nil {
return fmt.Errorf("error starting command '%s' : %s", s, err)
}
err = cmd.Wait()
if err != nil {
return fmt.Errorf("error waiting for command '%s': %s", s, err)
}
return nil
}