调用cmd时,Golang会调用cmd的返回值

func main() {
    cmd := exec.Command("python", "/t.py")
    cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
    cmd.Stdout = os.Stdout
    cmd.Run()
    select {

    }
}

t.py

while True:
    print("22222")
    time.sleep(1)

It will not output at any time, python program must exit, or golang will exit?

I expect golang to call CMD to execute Python program and get the return value of CMD at all times. It should be the problem of line buffer。

When I use Python call, there is no line buffer problem.

import os

r1, w1 = os.pipe()
pid = os.fork()

if pid:
    print("p")
    r1 = os.fdopen(r1)
    while 1:
        str = r1.read(1)
        print(str, end="")
else:
    os.dup2(w1, 1)
    os.dup2(w1, 2)
    os.execve("/Users/hulingjie/.env1/bin/python", ["python", "/t.py"], os.environ.copy())