old blog,

Tee'ing Python subprocess.Popen output

Izhar Firdaus Izhar Firdaus Follow Support Feb 28, 2008 · 1 min read
Tee'ing Python subprocess.Popen output
Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.
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.


import sys
from subprocess import Popen,PIPE
p = Popen(['put','command','and','arguments','here'],stdout=PIPE)

while True:
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
Written by Izhar Firdaus Follow Support
I'm a system architect, data engineer and developer advocate 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.

Calling all Malaysian Fedora users and contributors

Fedora presence in Malaysia is quite hidden from the general public. Fedora users in Malaysia are everywhere, but hard to find due to...

In old blog, Feb 26, 2008

« Previous Post

Hacks: find_changed_rpms.py

Sometimes, we might be facing certain problems which we could not find what might have caused it. One of the annoying cause is a brok...

In old blog, Feb 28, 2008

Next Post »