Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import subprocess, select
- tsk = subprocess.Popen(['/usr/bin/python', 'outputs.py'],stdout=subprocess.PIPE,stderr=subprocess.PIPE)
- poll = select.poll()
- poll.register(tsk.stdout,select.POLLIN | select.POLLHUP)
- poll.register(tsk.stderr,select.POLLIN | select.POLLHUP)
- pollc = 2
- ot = []
- events = poll.poll()
- while pollc > 0 and len(events) > 0:
- for event in events:
- (rfd,event) = event
- if event & select.POLLIN:
- if rfd == tsk.stdout.fileno():
- line = tsk.stdout.readline()
- if len(line) > 0:
- ot.append(line[:-1])
- print line[:-1]
- continue
- if rfd == tsk.stderr.fileno():
- line = tsk.stderr.readline()
- if len(line) > 0:
- ot.append("!"+line[:-1])
- print "!" + line[:-1]
- continue
- if event & select.POLLHUP:
- poll.unregister(rfd)
- pollc = pollc - 1
- if pollc > 0: events = poll.poll()
- tsk.wait()
- print ot
Add Comment
Please, Sign In to add comment