putting text through pager

Michael Goerz newsgroup898sfie at 8439.e4ward.com
Thu Mar 20 16:43:20 EDT 2008


Hi,

I'm trying to print some variable through a pager (i.e. 'less') on a 
linux system. My attempt was this:


====== snip here ======
import subprocess

def put_through_pager(displaystring):
     less_pipe = subprocess.Popen(\
                     'less', shell=True, \
                      stdin=subprocess.PIPE).stdin
     less_pipe.write(displaystring)
     less_pipe.close()

def main():
     put_through_pager(longstring)


longstring = """
Lorem ipsum dolor sit amet,...
http://www.lipsum.com/
"""

main()

====== snip here ======

That doesn't work however: first of all, it only flashes the text for a 
fraction of a second, and secondly, after I run the program my terminal 
is broken, not echoing whatever I type back to me.

Any suggestions for putting text through a pager from Python? This is 
strictly on a linux system, of course.

Thanks,
Michael



More information about the Python-list mailing list