我正在使用Google Cloud Run来运行应用程序(例如示例应用程序),我在Go中有以下脚本:package mainimport ( "fmt" "log" "net/http" "os" "os/exec")func handler(w http.ResponseWriter, r *http.Request) { log.Print("helloworld: received a request") cmd := exec.CommandContext(r.Context(), "/bin/sh", "script.sh") cmd.Stderr = os.Stderr out, err := cmd.Output() if err != nil { w.WriteHeader(500) } w.Write(out)}func main() { log.Print("helloworld: starting server...") http.HandleFunc("/", handler) port := os.Getenv("PORT") if port == "" { port = "8080" } log.Printf("helloworld: listening on %s", port) log.Fatal(http.ListenAndServe(fmt.Sprintf(":%s", port), nil))}我需要从 script.sh 命令中记录.print响应正文。我该怎么做?
- 1 回答
- 0 关注
- 499 浏览
添加回答
举报
0/150
提交
取消