@module.client_handler(MODNAME)
def client(client, inp):
    """Posh `shell' command client-side.

    Create a subprocess for command and line buffer command output to
    server while listening for signals from server.

    Args:
        s: PoetSocketClient instance
    """

    # get rid of 'shell ' prefix sent from client
    inp = inp[6:]

    # handle cd builtin
    _inp = inp.split()
    if _inp[0] == 'cd':
        if len(_inp) == 1:
            os.chdir(os.path.expanduser('~'))
        else:
            try:
                os.chdir(os.path.expanduser(_inp[1]))
            except __HOLE__ as e:
                client.s.send('cd: {}\n'.format(e.strerror))
        shelldone(client)
        return

    # everything else
    proc = sp.Popen(inp, stdout=sp.PIPE, stderr=sp.STDOUT, shell=True)
    while True:
        readable = select.select([proc.stdout, client.s.s], [], [], 30)[0]
        for fd in readable:
            if fd == proc.stdout:  # proc has stdout/err to send
                output = proc.stdout.readline()
                if output:
                    client.s.send(output)
                else:
                    shelldone(client)
                    return
            elif fd == client.s.s:  # remote signal from server
                sig = client.s.recv()
                if sig == 'shellterm':
                    proc.terminate()
                    shelldone(client)
                    return
dataset/ETHPy150Open mossberg/poet/poet/modules/shell.py/client