Try to resolve #171

This commit is contained in:
Liang Ding 2014-12-23 10:44:27 +08:00
parent 594a02115b
commit 9a49f753d9
1 changed files with 16 additions and 8 deletions

View File

@ -112,8 +112,8 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
data["succ"] = false
}
outReader := util.NewReader(stdout)
errReader := util.NewReader(stderr)
outReader := bufio.NewReader(stdout)
errReader := bufio.NewReader(stderr)
if err := cmd.Start(); nil != err {
logger.Error(err)
@ -167,12 +167,18 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
go func() {
for {
buf, err := outReader.ReadData()
r, _, err := outReader.ReadRune()
if nil == session.OutputWS[sid] {
break
}
wsChannel := session.OutputWS[sid]
buf := string(r)
buf = strings.Replace(buf, "<", "&lt;", -1)
buf = strings.Replace(buf, ">", "&gt;", -1)
// TODO: fix the duplicated error
if nil != err {
// remove the exited process from user process set
processes.remove(wSession, cmd.Process)
@ -209,9 +215,7 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
}()
for {
buf, err := errReader.ReadData()
buf = strings.Replace(buf, "<", "&lt;", -1)
buf = strings.Replace(buf, ">", "&gt;", -1)
r, _, err := errReader.ReadRune()
if nil == session.OutputWS[sid] {
break
@ -219,6 +223,10 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
wsChannel := session.OutputWS[sid]
buf := string(r)
buf = strings.Replace(buf, "<", "&lt;", -1)
buf = strings.Replace(buf, ">", "&gt;", -1)
if nil != err {
// remove the exited process from user process set
processes.remove(wSession, cmd.Process)