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.
tee
and compare file to screen... – RudiC Feb 09 '20 at 11:05ls
changes columnising,grep
suppresses colouring, etc. One of your team has perhaps outsmarted themselves. Also, streams can be buffered differently (automatically) depending on what they are connected to. Consider running the code understdbuf
to disable buffering (although the code can also over-ride this too). You should probably get somebody outside the team to audit it. – Paul_Pedant Feb 09 '20 at 12:57output.txt
has control characters in it, which are preventing it being displayed properly (withcat
)? For instance, theclear screen
codes. This would makecat
clear the screen and you miss the preceding output. I almost never usecat
- I recommend the use ofless
or an editor likevi
to see the file in the raw. – Gedge Feb 11 '20 at 00:17