from subprocess import Popen,PIPE
p = Popen(['put','command','and','arguments','here'],stdout=PIPE)
o = p.stdout.readline()
if o == '' and p.poll() != None: break
# the 'o' variable stores a line from the command's stdout
# do anything u wish with the 'o' variable here
# this loop will break once theres a blank output
# from stdout and the subprocess have ended
Thursday, February 28, 2008
Tee'ing Python subprocess.Popen output
A little hack for python coders out there who wanted to have a functionality similar to the unix's tee command for redirecting output to multiple places.
A system/solution engineer with passion in Free / Open Source software, entrepreneurship, community building, education and martial art. I take enjoyment in bridging and bringing together different FOSS technologies to help businesses and organizations utilize IT infrastructure to aid and optimize their business and organizational process.