我正在使用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 關注
- 549 瀏覽
添加回答
舉報
0/150
提交
取消
