This commit is contained in:
Tim Van Baak 2025-01-16 06:38:31 -08:00
parent 7aae56415d
commit a3d898aa50
2 changed files with 41 additions and 0 deletions

1
.envrc
View File

@ -1 +1,2 @@
layout go
use flake

40
main.go Normal file
View File

@ -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
}