Commit be9ad02d authored by Mathieu Giraud's avatar Mathieu Giraud

tools/ unbuffered

parent 918dd37f
...@@ -19,15 +19,22 @@ parser.add_argument('file', nargs='*', help='''output file(s)''') ...@@ -19,15 +19,22 @@ parser.add_argument('file', nargs='*', help='''output file(s)''')
def unbuffered_read(f):
# see
l = f.readline()
while l:
yield l
l = f.readline()
def tee(cmd, outputs): def tee(cmd, outputs):
'''Runs 'cmd', pipe the output to 'outputs', and returns the exit code of 'cmd' ''' '''Runs 'cmd', pipe the output to 'outputs', and returns the exit code of 'cmd' '''
argz = shlex.split(cmd) argz = shlex.split(cmd)
p = subprocess.Popen(argz, p = subprocess.Popen(argz,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
close_fds=True) close_fds=True)
for l in p.stdout: for l in unbuffered_read(p.stdout):
for o in outputs: for o in outputs:
o.write(l) o.write(l)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment