I want to write the 'top' command's output to another file. But when I tried it with the below code, I get the below error:
'exit status 1'.
Here is my code:
package main
import "os/exec"
func main() {
app := "top"
cmd := exec.Command(app)
stdout, err := cmd.Output()
if err != nil {
println(err.Error())
return
}
print(string(stdout))
}
Any help is greatly appreciated. Thanks in advance.