I recently implemented a progress bar class in C++. I wrote something like
cout << "\r" << percentage_done << "%" << flush;
Now I am running some programs piping the output to less.
The problem is that less shows me a lot of lines of the type
^M1%^M2%…
So the “\r” is not interpreted correctly. Is it possible to pipe this in such a way
that less will only show the final 100% line or do I have to add a switch to my program
to disable the progression bars entirely?
I have the same problem when I pipe the output directly to a file, so the output files
occupy a lot of disk space unnecessarily.
Well, I think that it was quite right what Jan Hudec said. I wrote myself a small function
Depending on the return value I either print the progression bar or not. Now everything works quite nicely 🙂