diff --git a/internal/edgeapps/edgeapps.go b/internal/edgeapps/edgeapps.go index d9a24b9..bdb757a 100644 --- a/internal/edgeapps/edgeapps.go +++ b/internal/edgeapps/edgeapps.go @@ -265,7 +265,7 @@ func DisableOnline(ID string) MaybeEdgeApp { func buildFrameworkContainers() { cmdArgs := []string{utils.GetPath("wsPath") + "ws", "--build"} - utils.Exec("sh", cmdArgs) + utils.ExecAndStream("sh", cmdArgs) time.Sleep(defaultContainerOperationSleepTime) diff --git a/internal/utils/utils.go b/internal/utils/utils.go index 0fd74c1..50cdb96 100644 --- a/internal/utils/utils.go +++ b/internal/utils/utils.go @@ -3,12 +3,35 @@ package utils import ( "bytes" "fmt" + "io" "log" + "os" "os/exec" "github.com/joho/godotenv" ) +// ExecAndStream : Runs a terminal command, but streams progress instead of outputting. Ideal for long lived process that need to be logged. +func ExecAndStream(command string, args []string) { + + cmd := exec.Command(command, args...) + + var stdoutBuf, stderrBuf bytes.Buffer + cmd.Stdout = io.MultiWriter(os.Stdout, &stdoutBuf) + cmd.Stderr = io.MultiWriter(os.Stderr, &stderrBuf) + cmd.Dir = GetPath("wsPath") + + err := cmd.Run() + + if err != nil { + log.Fatalf("cmd.Run() failed with %s\n", err) + } + + outStr, errStr := string(stdoutBuf.Bytes()), string(stderrBuf.Bytes()) + fmt.Printf("\nout:\n%s\nerr:\n%s\n", outStr, errStr) + +} + // Exec : Runs a terminal Command, catches and logs errors, returns the result. func Exec(command string, args []string) string { cmd := exec.Command(command, args...)