Skip to content

Commit

Permalink
[Fix] When shell command exec error, we also want to know the previou…
Browse files Browse the repository at this point in the history
…s stdout (#86)

* [Fix] When shell command exec error, we also want to know the previous stdout

* fix unit test error
  • Loading branch information
aaawuanjun committed Oct 17, 2022
1 parent cb88099 commit 94e50c0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions shell2http.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,13 @@ func getShellHandler(appConfig Config, shell string, params []string, cacheTTL r
return func(rw http.ResponseWriter, req *http.Request) {
shellOut, exitCode, err := execShellCommand(appConfig, shell, params, req, cacheTTL)
if err != nil {
log.Println("exec error: ", err)
log.Println(string(shellOut), "\nexec error: ", err)
}

rw.Header().Set("X-Shell2http-Exit-Code", strconv.Itoa(exitCode))

if err != nil && !appConfig.showErrors {
responseWrite(rw, "exec error: "+err.Error())
responseWrite(rw, string(shellOut)+"\nexec error: "+err.Error())
} else {
outText := string(shellOut)
if appConfig.setCGI {
Expand Down
2 changes: 1 addition & 1 deletion shell2http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func Test_main(t *testing.T) {
)

testHTTP(t, "GET", "http://localhost:"+port+"/error", "",
func(res string) bool { return strings.HasPrefix(res, "exec error:") },
func(res string) bool { return strings.Contains(res, "exec error:") },
"5. error",
)

Expand Down

0 comments on commit 94e50c0

Please sign in to comment.