from subprocess import Popen, PIPE, STDOUT installer = Popen(['aptitude', 'update'], stdout=PIPE, stderr=STDOUT) for line in installer.stdout: line = line.lower() print line if line.startswith("err") or "failed" in line or "failure" in line: pass