Hi everyone,
I used exec.Command to call the Linux commands and send the response as http response body.
out, _ = cmd.Output()
return Response{string(out)}, nil
When I display the response with pre
and code
tags in my HTML page, it doesn’t show correctly.
output of exec.Command: stdout.png
What showed in my web page:
File C:\tmp
e[38;5;41m e should existe[0m
File C:\tmp\AP_prod_W2k16_JP
e[38;5;41m e should existe[0m
I also confirmed that if copy the stdout and hard-code it as response, it shows perfectly in my web page.
str := `
File C:\tmp
✔ should exist
File C:\tmp\AP_prod_W2k16_JP
✔ should exist`
return Response{str}, nil
It seems to me the issue was caused by the font styling in the stdout.
My question is: how to make it show correctly in my web page in this case? Is there a way to eliminate the color/style when casting to string in Golang, or a way to preserve the style in my html page?