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