Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jul 25th, 2011  |  syntax: Python  |  size: 0.93 KB  |  views: 72  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import subprocess, select
  2.  
  3. tsk = subprocess.Popen(['/usr/bin/python', 'outputs.py'],stdout=subprocess.PIPE,stderr=subprocess.PIPE)
  4.  
  5. poll = select.poll()
  6. poll.register(tsk.stdout,select.POLLIN | select.POLLHUP)
  7. poll.register(tsk.stderr,select.POLLIN | select.POLLHUP)
  8. pollc = 2
  9. ot = []
  10. events = poll.poll()
  11. while pollc > 0 and len(events) > 0:
  12.   for event in events:
  13.     (rfd,event) = event
  14.     if event & select.POLLIN:
  15.       if rfd == tsk.stdout.fileno():
  16.         line = tsk.stdout.readline()
  17.         if len(line) > 0:
  18.           ot.append(line[:-1])
  19.           print line[:-1]
  20.           continue
  21.       if rfd == tsk.stderr.fileno():
  22.         line = tsk.stderr.readline()
  23.         if len(line) > 0:
  24.           ot.append("!"+line[:-1])
  25.           print "!" + line[:-1]
  26.           continue
  27.     if event & select.POLLHUP:
  28.       poll.unregister(rfd)
  29.       pollc = pollc - 1
  30.     if pollc > 0: events = poll.poll()
  31. tsk.wait()
  32. print ot