update
commit
1fed7493c5
|
@ -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)
|
||||
}
|
Loading…
Reference in New Issue