(text, cmd)
Page through text by feeding it to another program.
Page through text by feeding it to another program.
Page through text by feeding it to another program .
def pipepager(text, cmd):
    """Page through text by feeding it to another program."""
    import subprocess
    proc = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE,
                            errors='backslashreplace')
    try:
        with proc.stdin as pipe:
            try:
                pipe.write(text)
            except KeyboardInterrupt:
                # We've hereby abandoned whatever text hasn't been written,
                # but the pager is still in control of the terminal.
                pass
    except OSError:
        pass # Ignore broken pipes caused by quitting the pager program.
    while True:
        try:
            proc.wait()
            break
        except KeyboardInterrupt:
            # Ignore ctl-c like the pager itself does.  Otherwise the pager is
            # left running and the terminal is in raw mode and unusable.
            pass
def pipepager ( text , cmd ) : import subprocess proc = subprocess . Popen ( cmd , shell = True , stdin = subprocess . PIPE , errors = 'backslashreplace' ) try : with proc . stdin as pipe : try : pipe . write ( text ) except KeyboardInterrupt : # We've hereby abandoned whatever text hasn't been written, # but the pager is still in control of the terminal. pass except OSError : pass # Ignore broken pipes caused by quitting the pager program. while True : try : proc . wait ( ) break except KeyboardInterrupt : # Ignore ctl-c like the pager itself does.  Otherwise the pager is # left running and the terminal is in raw mode and unusable. pass