优化 运行 command 的稳定性

This commit is contained in:
dengsgo 2019-01-03 10:41:23 +08:00
parent 27f934d6fb
commit 09b1de75b3

View File

@ -45,7 +45,7 @@ func (t *TaskMan) Put(cf *changedFile) {
} }
func (t *TaskMan) preRun(cf *changedFile) { func (t *TaskMan) preRun(cf *changedFile) {
if t.cmd != nil { if t.cmd != nil && t.cmd.Process != nil {
err := t.cmd.Process.Kill() err := t.cmd.Process.Kill()
if err != nil { if err != nil {
log.Println("err: ", err) log.Println("err: ", err)
@ -74,7 +74,10 @@ func (t *TaskMan) run(cf *changedFile) {
log.Println("error=>", err.Error()) log.Println("error=>", err.Error())
return return
} }
_ = t.cmd.Start() err = t.cmd.Start()
if err != nil {
log.Println("run command", carr, "error. ", err)
}
reader := bufio.NewReader(stdout) reader := bufio.NewReader(stdout)
for { for {
line, err2 := reader.ReadString('\n') line, err2 := reader.ReadString('\n')
@ -88,11 +91,12 @@ func (t *TaskMan) run(cf *changedFile) {
log.Println("cmd wait err ", err) log.Println("cmd wait err ", err)
break break
} }
err = t.cmd.Process.Kill() if t.cmd.Process != nil {
if err != nil { if err = t.cmd.Process.Kill(); err != nil {
log.Println("cmd cannot kill ", err) log.Println("cmd cannot kill ", err)
} }
} }
}
log.Println("end ") log.Println("end ")
} }