亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在讀取 stdout 時保留 shell 腳本行距?

如何在讀取 stdout 時保留 shell 腳本行距?

Go
侃侃無極 2023-07-31 16:49:12
我正在 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 回答

?
翻翻過去那場雪

TA貢獻2065條經驗 獲得超14個贊

查看源碼,會發現模板保留了空格。問題在于瀏覽器正在折疊空白序列。


查看完整回答
反對 回復 2023-07-31
  • 1 回答
  • 0 關注
  • 104 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號