From 0d7205defb699fca810ba00817b500e00d8cf606 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Thu, 16 Oct 2014 10:39:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9E=84=E5=BB=BA&=E8=BF=90=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- output/outputs.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/output/outputs.go b/output/outputs.go index ab18d60..74841dd 100644 --- a/output/outputs.go +++ b/output/outputs.go @@ -111,9 +111,26 @@ func RunHandler(w http.ResponseWriter, r *http.Request) { go func(runningId int) { defer util.Recover() + defer cmd.Wait() glog.V(3).Infof("Session [%s] is running [id=%d, file=%s]", sid, runningId, filePath) + // 在读取程序输出前先返回一次,使前端获取到 run 状态以及对应的 pid + if nil != session.OutputWS[sid] { + wsChannel := session.OutputWS[sid] + + channelRet["cmd"] = "run" + channelRet["output"] = "" + err := wsChannel.Conn.WriteJSON(&channelRet) + if nil != err { + glog.Error(err) + return + } + + // 更新通道最近使用时间 + wsChannel.Time = time.Now() + } + for { buf := make([]byte, 1024) count, err := reader.Read(buf)