master
Evan Chen 2021-11-11 00:05:31 +08:00
commit 1fed7493c5
1 changed files with 45 additions and 0 deletions

45
main.go Normal file
View File

@ -0,0 +1,45 @@
package main
import (
"bufio"
"fmt"
"os/exec"
"sync"
"time"
)
func main() {
cmd := exec.Command("configui", "-p", "main.go")
out, _ := cmd.StdoutPipe()
stderr, _ := cmd.StderrPipe()
cmd.Start()
defer cmd.Process.Kill()
fmt.Println("start: ", cmd.Args, ", pid: ", cmd.Process.Pid)
<-time.After(time.Second * 1)
var outlock sync.Mutex
scanner := bufio.NewScanner(out)
go func() {
for {
<-time.After(time.Second)
fmt.Println("Usage: ", cmd.ProcessState.SysUsage())
}
}()
go func() {
for scanner.Scan() {
m := scanner.Text()
outlock.Lock()
fmt.Println(m)
outlock.Unlock()
}
}()
scannererr := bufio.NewScanner(stderr)
go func() {
for scannererr.Scan() {
m := scannererr.Text()
outlock.Lock()
fmt.Println(m)
outlock.Unlock()
}
}()
<-time.After(time.Second * 20)
}