构建&运行

This commit is contained in:
Liang Ding 2014-10-16 10:39:09 +08:00
parent d5360af414
commit 0d7205defb
1 changed files with 17 additions and 0 deletions

View File

@ -111,9 +111,26 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
go func(runningId int) { go func(runningId int) {
defer util.Recover() defer util.Recover()
defer cmd.Wait()
glog.V(3).Infof("Session [%s] is running [id=%d, file=%s]", sid, runningId, filePath) 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 { for {
buf := make([]byte, 1024) buf := make([]byte, 1024)
count, err := reader.Read(buf) count, err := reader.Read(buf)