From 651bb19a93cd1e16282555a04a21592413368a21 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Thu, 23 Oct 2014 15:02:33 +0800 Subject: [PATCH] . --- output/outputs.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/output/outputs.go b/output/outputs.go index 9198579..a961dda 100644 --- a/output/outputs.go +++ b/output/outputs.go @@ -5,6 +5,7 @@ import ( "bufio" "encoding/json" "io" + "io/ioutil" "math/rand" "net/http" "os" @@ -287,7 +288,7 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) { wsChannel.Time = time.Now() } - reader := io.MultiReader(stdout, stderr) + reader := bufio.NewReader(io.MultiReader(stdout, stderr)) if err := cmd.Start(); nil != err { glog.Error(err) @@ -303,14 +304,13 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) { glog.V(3).Infof("Session [%s] is building [id=%d, dir=%s]", sid, runningId, curDir) // 一次性读取 - buf := make([]byte, 1024*8) - count, _ := reader.Read(buf) + buf, _ := ioutil.ReadAll(reader) channelRet := map[string]interface{}{} channelRet["cmd"] = "build" channelRet["executable"] = executable - if 0 == count { // 说明构建成功,没有错误信息输出 + if 0 == len(buf) { // 说明构建成功,没有错误信息输出 // 设置下一次执行命令(前端会根据该参数发送请求) channelRet["nextCmd"] = args["nextCmd"] channelRet["output"] = "" + i18n.Get(r, "build-succ").(string) + "\n" @@ -328,7 +328,7 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) { }() } else { // 构建失败 // 解析错误信息,返回给编辑器 gutter lint - errOut := string(buf[:count]) + errOut := string(buf) channelRet["output"] = "" + i18n.Get(r, "build-failed").(string) + "\n" + errOut lines := strings.Split(errOut, "\n")