import subprocess import fcntl import select import os fproc = subprocess.Popen(["/usr/games/frotz", "ZORK1.DAT"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) fl = fcntl.fcntl(fproc.stdin, fcntl.F_GETFL) fl = fl | os.O_NONBLOCK fcntl.fcntl(fproc.stdin, fcntl.F_SETFL, fl) fl = fcntl.fcntl(fproc.stdout, fcntl.F_GETFL) fl = fl | os.O_NONBLOCK fcntl.fcntl(fproc.stdout, fcntl.F_SETFL, fl) while 1 == 1: ifd, ofd, efd = select.select([fproc.stdout], [], []) if fproc.stdout in ifd: for line in fproc.stdout: print line