Skip to content

Commit

Permalink
Send filter output through logs
Browse files Browse the repository at this point in the history
  • Loading branch information
stirante committed Sep 25, 2021
1 parent eded92c commit 5a33d13
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions regolith/utils.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package regolith

import (
"bufio"
"errors"
"fmt"
"io"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -32,9 +34,18 @@ func GetAbsoluteWorkingDirectory() string {
func RunSubProcess(command string, args []string, absoluteLocation string, workingDir string) error {
cmd := exec.Command(command, args...)
cmd.Dir = workingDir
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
out, _ := cmd.StdoutPipe()
err, _ := cmd.StderrPipe()
go LogStd(out, Logger.Infof)
go LogStd(err, Logger.Errorf)
cmd.Env = append(os.Environ(), "FILTER_DIR="+absoluteLocation)

return cmd.Run()
}

func LogStd(in io.ReadCloser, logFunc func(template string, args ...interface{})) {
scanner := bufio.NewScanner(in)
for scanner.Scan() {
logFunc("[Filter] %s", scanner.Text())
}
}

0 comments on commit 5a33d13

Please sign in to comment.