package main import ( "bufio" "fmt" "os/exec" ) func main() { cmd := exec.Command("ls", "-l") stdout, err := cmd.StdoutPipe() if err != nil { panic(err) } if err := cmd.Start(); err != nil { panic(err) } scanner := bufio.NewScanner(stdout) for scanner.Scan() { fmt.Println(scanner.Text()) } if err := scanner.Err(); err != nil { panic(err) } if err := cmd.Wait(); err != nil { panic(err) } }
package main import ( "bufio" "fmt" "os/exec" ) func main() { cmd := exec.Command("python3", "script.py") stdout, err := cmd.StdoutPipe() if err != nil { panic(err) } if err := cmd.Start(); err != nil { panic(err) } scanner := bufio.NewScanner(stdout) for scanner.Scan() { fmt.Println(scanner.Text()) } if err := scanner.Err(); err != nil { panic(err) } if err := cmd.Wait(); err != nil { panic(err) } }This example uses Cmd StdoutPipe to capture the output of a Python script and prints it to the console. Package: "os/exec" In both examples, the package used is "os/exec".