这是最后对我有用的解决方案(由qarma建议):
libc = ctypes.CDLL('libc.so.6')master, slave = pty.openpty()p = subprocess.Popen(["/bin/bash", "-i"], preexec_fn=libc.setsid, stdin=slave, stdout=slave, stderr=slave)os.close(slave)... do stuff here ...x = os.read(master, 1026)print x


