Require cmd.Exec output to be sent to console and a file
dineshdh opened this issue · comments
dineshdh commented
Why
I have a requirement where I need to generate a report and upload it to an evidence store. Having the CI pipeline pass/fail is not sufficient. I want to know how I can output the cmd.Exec output to a file as well as the console
What
Here is what I have so far
var lint = goyek.Define(goyek.Task{
Name: "lint",
Usage: "Preferred way to lint dashboards",
Action: func(a *goyek.A) {
cmd.Exec(a, "go test dashboards_test.go -v", cmd.Dir("../dashboards"))
},
})
I really don't have a suggestion , and I'm sure there is a sensible way to achieve what I want, just not obvious to me at the moment.
Alternatives
Other
Robert Pająk commented
You can use https://pkg.go.dev/io#MultiWriter to write to multiple outputs.
You can use https://pkg.go.dev/github.com/goyek/x/cmd#Stdout and
https://pkg.go.dev/github.com/goyek/x/cmd#Stderr to configure cmd.Exec
streams.