To clarify some of the answers.
rubyorpythonor any sensible scripting language will buffer the output; this is in order to minimize the IO; writing to disk is slow, writing to a console is slow...- usually the data gets
flush()'ed automatically after you have enough data in the buffer with special handling for newlines. e.g. writing a string without newline thensleep()would not write anything until after thesleep()is complete (I'm only usingsleepas an example, feel free to substitute with any other expensive system call).
e.g. this would wait 8 seconds, print one line, wait 5 more seconds, print a second line.
from time import sleep def test(): print "ok", time.sleep(3) print "now", time.sleep(5) print "done" time.sleep(5) print "again" test() for
ruby,STDOUT.sync = trueSTDOUT.sync = true, turns theautoflushon; all writes toSTDOUTare followed byflush(). This would solve your problem but result in more IO.STDOUT.sync = truefor
python, you can usepython -uor the environment variablePYTHONUNBUFFEREDto makestdin/stdout/stoutnot buffered, but there are other solutionsthere are other solutions that do not changestdinorstderrexport PYTHONUNBUFFERED=1for
perl, you haveautoflushautoflushautoflush STDOUT 1;