I'm trying to redirect the output of my program to a file. The program prints a few lines in the screen from time to time, and keeps proceeding like that until it terminates. When it terminates, the number of printed lines will be in the thousands.
When executing the program without any redirection directive, it prints all information in the screen as it should. Nevertheless, when trying to use >, or 1> or 2> or several other possibilities, one of two things happens. Either the output file stays completely empty, or it contains only the first 30 lines or so (which is enough to fill a page). I have also trying to redirect using " | cat >" and again nothing happens.
What could be the source of the problem? I'm using ubuntu and executing the program from the terminal. The program is compiled in C++, and text is printed using "cout".
Examples of redirections that I tried to use without success.
- ./testProgram > output.txt
- ./testProgram 1> output.txt
- ./testProgram 2> output.txt
- ./testProgram &> output.txt
- ./testProgram > output.txt 2>&1
- ./testProgram | cat > output.txt
- All variations above with >> instead of > also have the same problem
Obs: Since the computation may take some days, I use cat output.txt to see the file from time to time. Nevertheless, as mentioned above, only the first page or so of text is written at the file and that is all I can see. Since this amount of text corresponds to executing the program for a few seconds, it doesn't seem that reading the file is the cause of the problem.