fix build & run stderr output
This commit is contained in:
parent
c7f702cd15
commit
8b7fdaaace
|
@ -96,7 +96,8 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
reader := bufio.NewReader(io.MultiReader(stdout, stderr))
|
outReader := bufio.NewReader(stdout)
|
||||||
|
errReader := bufio.NewReader(stderr)
|
||||||
|
|
||||||
if err := cmd.Start(); nil != err {
|
if err := cmd.Start(); nil != err {
|
||||||
glog.Error(err)
|
glog.Error(err)
|
||||||
|
@ -132,14 +133,57 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
wsChannel.Refresh()
|
wsChannel.Refresh()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
go func() {
|
||||||
for {
|
for {
|
||||||
buf, err := reader.ReadBytes('\n')
|
buf, err := outReader.ReadString('\n')
|
||||||
|
|
||||||
if nil != err || 0 == len(buf) {
|
if nil != err {
|
||||||
// remove the exited process from user process set
|
// remove the exited process from user process set
|
||||||
processes.remove(wSession, cmd.Process)
|
processes.remove(wSession, cmd.Process)
|
||||||
|
|
||||||
glog.V(3).Infof("Session [%s] 's running [id=%d, file=%s] has done", sid, runningId, filePath)
|
glog.V(3).Infof("Session [%s] 's running [id=%d, file=%s] has done [stdout err]", sid, runningId, filePath)
|
||||||
|
|
||||||
|
if nil != session.OutputWS[sid] {
|
||||||
|
wsChannel := session.OutputWS[sid]
|
||||||
|
|
||||||
|
channelRet["cmd"] = "run-done"
|
||||||
|
channelRet["output"] = "<pre>" + string(buf) + "</pre>"
|
||||||
|
err := wsChannel.Conn.WriteJSON(&channelRet)
|
||||||
|
if nil != err {
|
||||||
|
glog.Error(err)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
wsChannel.Refresh()
|
||||||
|
}
|
||||||
|
|
||||||
|
break
|
||||||
|
} else {
|
||||||
|
if nil != session.OutputWS[sid] {
|
||||||
|
wsChannel := session.OutputWS[sid]
|
||||||
|
|
||||||
|
channelRet["cmd"] = "run"
|
||||||
|
channelRet["output"] = "<pre>" + string(buf) + "</pre>"
|
||||||
|
err := wsChannel.Conn.WriteJSON(&channelRet)
|
||||||
|
if nil != err {
|
||||||
|
glog.Error(err)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
wsChannel.Refresh()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
for {
|
||||||
|
buf, err := errReader.ReadString('\n')
|
||||||
|
|
||||||
|
if nil != err {
|
||||||
|
// remove the exited process from user process set
|
||||||
|
processes.remove(wSession, cmd.Process)
|
||||||
|
|
||||||
|
glog.V(3).Infof("Session [%s] 's running [id=%d, file=%s] has done [stderr err]", sid, runningId, filePath)
|
||||||
|
|
||||||
if nil != session.OutputWS[sid] {
|
if nil != session.OutputWS[sid] {
|
||||||
wsChannel := session.OutputWS[sid]
|
wsChannel := session.OutputWS[sid]
|
||||||
|
|
Loading…
Reference in New Issue