This commit is contained in:
Liang Ding 2014-10-23 14:44:06 +08:00
parent 7cf4376489
commit 4803025da1
1 changed files with 6 additions and 6 deletions

View File

@ -2,6 +2,7 @@
package output package output
import ( import (
"bufio"
"encoding/json" "encoding/json"
"io" "io"
"math/rand" "math/rand"
@ -95,7 +96,7 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
return return
} }
reader := io.MultiReader(stdout, stderr) reader := bufio.NewReader(io.MultiReader(stdout, stderr))
if err := cmd.Start(); nil != err { if err := cmd.Start(); nil != err {
glog.Error(err) glog.Error(err)
@ -133,10 +134,9 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
} }
for { for {
buf := make([]byte, 1024) buf, err := reader.ReadBytes('\n')
count, err := reader.Read(buf)
if nil != err || 0 == count { if nil != err || 0 == len(buf) {
// 从用户进程集中移除这个执行完毕(或是被主动停止)的进程 // 从用户进程集中移除这个执行完毕(或是被主动停止)的进程
processes.remove(wSession, cmd.Process) processes.remove(wSession, cmd.Process)
@ -146,7 +146,7 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
wsChannel := session.OutputWS[sid] wsChannel := session.OutputWS[sid]
channelRet["cmd"] = "run-done" channelRet["cmd"] = "run-done"
channelRet["output"] = "<pre>" + string(buf[:count]) + "</pre>" channelRet["output"] = "<pre>" + string(buf) + "</pre>"
err := wsChannel.Conn.WriteJSON(&channelRet) err := wsChannel.Conn.WriteJSON(&channelRet)
if nil != err { if nil != err {
glog.Error(err) glog.Error(err)
@ -163,7 +163,7 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
wsChannel := session.OutputWS[sid] wsChannel := session.OutputWS[sid]
channelRet["cmd"] = "run" channelRet["cmd"] = "run"
channelRet["output"] = "<pre>" + string(buf[:count]) + "</pre>" channelRet["output"] = "<pre>" + string(buf) + "</pre>"
err := wsChannel.Conn.WriteJSON(&channelRet) err := wsChannel.Conn.WriteJSON(&channelRet)
if nil != err { if nil != err {
glog.Error(err) glog.Error(err)