Introduced ExecAndStream for execution with progress output
parent
5e81525635
commit
0ffde681cf
|
@ -265,7 +265,7 @@ func DisableOnline(ID string) MaybeEdgeApp {
|
||||||
func buildFrameworkContainers() {
|
func buildFrameworkContainers() {
|
||||||
|
|
||||||
cmdArgs := []string{utils.GetPath("wsPath") + "ws", "--build"}
|
cmdArgs := []string{utils.GetPath("wsPath") + "ws", "--build"}
|
||||||
utils.Exec("sh", cmdArgs)
|
utils.ExecAndStream("sh", cmdArgs)
|
||||||
|
|
||||||
time.Sleep(defaultContainerOperationSleepTime)
|
time.Sleep(defaultContainerOperationSleepTime)
|
||||||
|
|
||||||
|
|
|
@ -3,12 +3,35 @@ package utils
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
|
||||||
"github.com/joho/godotenv"
|
"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.
|
// Exec : Runs a terminal Command, catches and logs errors, returns the result.
|
||||||
func Exec(command string, args []string) string {
|
func Exec(command string, args []string) string {
|
||||||
cmd := exec.Command(command, args...)
|
cmd := exec.Command(command, args...)
|
||||||
|
|
Loading…
Reference in New Issue