# -*- coding: iso8859-1 -*- # # Copyright (C) 2006 CSIRO Australia # All rights reserved. # # This software is licensed as described in the file COPYING, which # you should have received as part of this distribution. # # This software consists of voluntary contributions made by many # individuals. For exact contribution history, see the revision # history and logs. # # Author: Conrad Parker from popen2 import Popen4 # Limit the amount of data to read from the pipe pipe_limit = 1024*1024 class PipeOutput (object): def __init__(self, cmd, f): p = Popen4 (cmd) total = 0 while total < pipe_limit: chunk = f.read (10000) if not chunk: break; total += len(chunk) try: p.tochild.write (chunk) except IOError: pass p.tochild.close() self.output = p.fromchild.read() self.status = p.wait() def __str__(self): return self.output