writing consecutive data to subprocess command 'more'
SanPy
jhmsmits at gmail.com
Sat May 2 14:53:17 EDT 2009
I have this method that prints a given text via a subprocess command
'more' . It is like this:
def print_by_page(text):
if hasattr(sys.stdout, 'isatty') and sys.stdout.isatty():
viewer = 'more -EMR'
proc = subprocess.Popen([viewer], shell=True,
stdin=subprocess.PIPE,
stderr=subprocess.PIPE)
try:
stdout, stderr = proc.communicate(text)
except OSError:
pass
else:
if stderr: # probably no 'more' available on this system
sys.stdout.write(text)
return
sys.stdout.write(text)
It works fine, but what I really want to do is first print a header
through the 'more' command, then fetch some data from the web, and
show it through the same 'more' command/process. And even more data,
another header, other data from the web, all through the same 'more'
command/process.
Can somebody help me out on this?
Regards,
Sander Smits
More information about the Python-list
mailing list