def posix_shell(chan, raw):
    # set signal somehow
    import select

    oldtty = termios.tcgetattr(stdin_bytes)
    try:
        if raw:
            tty.setraw(stdin_bytes.fileno())
            tty.setcbreak(stdin_bytes.fileno())
        chan.settimeout(0.0)

        while True:
            r, w, e = select.select([chan, stdin_bytes], [], [])
            if chan in r:
                try:
                    if chan.recv_stderr_ready():
                        x = chan.recv_stderr(1024)
                        if len(x) > 0:
                            stderr_bytes.write(x)
                            stderr_bytes.flush()
                    else:
                        x = chan.recv(1024)
                        if len(x) == 0:
                            break
                        stdout_bytes.write(x)
                        stdout_bytes.flush()
                except socket.timeout:
                    pass
            if stdin_bytes in r:
                x = stdin_bytes.read(1)
                if len(x) == 0:
                    break
                chan.send(x)

    finally:
        if raw:
            termios.tcsetattr(stdin_bytes, termios.TCSADRAIN, oldtty)


# thanks to Mike Looijmans for this code
dataset/ETHPy150Open ViDA-NYU/reprozip/reprounzip-vagrant/reprounzip/unpackers/vagrant/interaction.py/posix_shell/original