Uppsala Multidisciplinary Center for Advanced Computational Science

I want my program to send data to both stdout and to a file but nothing comes until the program ends?

There is a program called unbuffer. You could try using it like (tee takes care of sending both to stdout and to a file):

unbuffer your_program |tee some_output_file