From 2e0fd09b43fab75628dce22ce49b5e968049b735 Mon Sep 17 00:00:00 2001 From: nojhan Date: Thu, 12 Jul 2012 14:01:59 +0200 Subject: [PATCH] print each line as soon as it is read --- colout.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/colout.py b/colout.py index 332c4cb..90eb2d6 100755 --- a/colout.py +++ b/colout.py @@ -111,11 +111,17 @@ if __name__ == "__main__": args = parser.parse_args() - for line in sys.stdin: - if not args.stderr: - print colorup( line, args.pattern[0], args.color, args.style ), - sys.stdout.flush() - else: - print >> sys.stderr, colorup( line, args.pattern[0], args.color, args.style ), - sys.stderr.flush() + while True: + line = sys.stdin.readline() + if line == '': + break + try: + if not args.stderr: + print colorup( line, args.pattern[0], args.color, args.style ), + sys.stdout.flush() + else: + print >> sys.stderr, colorup( line, args.pattern[0], args.color, args.style ), + sys.stderr.flush() + except: + pass