diff --git a/.envrc b/.envrc index 3550a30..5433df1 100644 --- a/.envrc +++ b/.envrc @@ -1 +1,2 @@ +layout go use flake diff --git a/main.go b/main.go new file mode 100644 index 0000000..7268dce --- /dev/null +++ b/main.go @@ -0,0 +1,40 @@ +package main + +import ( + "bufio" + "fmt" + "os/exec" + "strings" +) + +func main() { + fmt.Printf("Hello\n") + + cmd := exec.Command("sh", "-c", "echo Wout; sleep 1; echo 1>&2 Werr; sleep 1; echo Wout2; sleep 1; echo 1>&2 Werr2") + stdout, _ := cmd.StdoutPipe() + stderr, _ := cmd.StderrPipe() + + cout := make(chan int) + go func() { + scanout := bufio.NewScanner(stdout) + for scanout.Scan() { + text := strings.TrimSpace(scanout.Text()) + fmt.Printf("[stdout] %s\n", text) + } + cout <- 1 + }() + + cerr := make(chan int) + go func() { + scanerr := bufio.NewScanner(stderr) + for scanerr.Scan() { + text := strings.TrimSpace(scanerr.Text()) + fmt.Printf("[stderr] %s\n", text) + } + cerr <- 1 + }() + + cmd.Start() + <-cout + <-cerr +}