Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My issue is that I have a function call it function1 which runs indefinitely. The function itself echo's hello every second. Using the command:

function1 >> temp.txt

Every second if I am to view the file temp.txt I should see a new line with hello. However what's happening is that the function doesn't write to the file until its finished running. Therefore if I am to kill the function nothing will be written. Does anyone know of something I can do in this situation that will basically dynamically update temp.txt?

I have a python script set up the following way:

while [1>0]:
   print "hello"

Therefore this will always be running. Now I call this in a bash script

python >> temp.txt

If I kill the process no data is logged.

share|improve this question
Please include the source/context of function1. – izx Jul 20 '12 at 20:05
up vote 1 down vote accepted

Bash doesn't buffer, but python will buffer if output isn't going to a terminal (because it's more efficient), so you'll want to flush stdout after every line.

#!/usr/bin/env python
import sys
import time
while True:
    print "hello"
share|improve this answer
Works perfectly thank you! – Matt Stokes Jul 23 '12 at 14:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.