View difference between Paste ID: gScsiU9S and
SHOW: | | - or go back to the newest paste.
1-
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