我正在 Windows 10 上通過 Cygwin 執(zhí)行 shell 腳本,將 stdout 和 stderr 讀取為字符串,并將該字符串傳遞給用于執(zhí)行 html 模板的結(jié)構(gòu)。問題是執(zhí)行模板后不會保留輸出的間距。以下是我執(zhí)行命令并將命令輸出設(shè)置到我的數(shù)據(jù)結(jié)構(gòu)的方式。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 會產(chǎn)生類似這樣的結(jié)果,這正是我所期望的。顯示新行。If the same archived message file is in both system/logs and archived_logs, it will be searched/counted twice!====X1-SC1====Done運(yùn)行命令并更新我的數(shù)據(jù)結(jié)構(gòu)后,將使用 html 模板執(zhí)行數(shù)據(jù)。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/模板執(zhí)行似乎正在刪除額外的空白、行或類似的東西。有沒有解決的辦法?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 關(guān)注
- 109 瀏覽
添加回答
舉報
0/150
提交
取消