I aware we can collect the std returned command as:
package main
import (
"fmt"
"log"
"os/exec"
)
func main() {
out, err := exec.Command("date").Output()
if err != nil {
log.Fatal(err)
}
fmt.Printf("The date is %s\n", string(out))
}
Or something as:
package main
import (
"bytes"
"fmt"
"log"
"os/exec"
"strings"
)
func main() {
cmd := exec.Command("tr", "a-z", "A-Z")
cmd.Stdin = strings.NewReader("some input")
var out bytes.Buffer
cmd.Stdout = &out
err := cmd.Run()
if err != nil {
log.Fatal(err)
}
fmt.Printf("in all caps: %q\n", out.String())
}
But this is usually happening for the commands that complete, return an output and exit.
In my case, I’ve a command, from a running server, that is keep providing logs to the std, something as:
waLog.Stdout("Client", "ERROR", true)
Part of the output is below:
How can I catch this output inside my code, something like cmd.Stdout
above?