package main import ( "fmt" "os/exec" ) func main() { cmd := exec.Command("ls", "-al") out, err := cmd.Output() if err != nil { fmt.Println(err) return } fmt.Println(string(out)) }
package main import ( "fmt" "os/exec" "time" ) func main() { cmd := exec.Command("ping", "-c", "3", "google.com") timer := time.AfterFunc(time.Second*5, func() { cmd.Process.Kill() }) out, err := cmd.Output() timer.Stop() if err != nil { fmt.Println(err) return } fmt.Println(string(out)) }The package used is `os.exec`.