None of them worked for me. Python3.11 / Python3.12 Linux/Windows11
I get the stdout first, if the command is finished. For Linux I found:
p=pexpect.spawn(cmd) / p.read_nonblocking()
p=pexpect.spawn(cmd) / p.read_nonblocking()
But unfortunately, this doesn't work for Windows. I'm still searching for a solution for Windows.