我正在 Windows 10 上通過 Cygwin 執行 shell 腳本,將 stdout 和 stderr 讀取為字符串,并將該字符串傳遞給用于執行 html 模板的結構。問題是執行模板后不會保留輸出的間距。以下是我執行命令并將命令輸出設置到我的數據結構的方式。var outbuf, errbuf bytes.Buffercmd.Stdout = &outbufcmd.Stderr = &errbuferr = cmd.Run()if err != nil { log.Printf("Error running command: %s", err) data.Output = errbuf.String() return data}log.Printf("%v", outbuf.String())data.Output = outbuf.String()return datalog.Printf 會產生類似這樣的結果,這正是我所期望的。顯示新行。If the same archived message file is in both system/logs and archived_logs, it will be searched/counted twice!====X1-SC1====Done運行命令并更新我的數據結構后,將使用 html 模板執行數據。err = t.Execute(w, data)if err != nil { log.Println(err) w.WriteHeader(http.StatusInternalServerError) w.Write([]byte(fmt.Sprintf("Failed to execute html: %v", err))) return }}<div style="text-align:center"> {{.Output}}</div>瀏覽到我的項目公開的位置后,我看到了我期望的輸出,但它都在一行上。間距未保留。html/模板執行似乎正在刪除額外的空白、行或類似的東西。有沒有解決的辦法?If the same archived message file is in both system/logs and archived_logs, it will be searched/counted twice! Maybe it'll be fixed in the future.. ====X1-SC1==== Done
- 1 回答
- 0 關注
- 104 瀏覽
添加回答
舉報
0/150
提交
取消