You are indeed "suffering from buffering". STDOUT will typically be buffered with n Kbytes of stuff before the buffer is actually written to the disk or to the console. n might be 1,2,4, which could be a lot of lines!

$|=1; or $|++; will turn off buffering globally and that might not be what you want because it will slow down disk writes. I guess this could be called a "cheater method", but if you 'print STDERR "progress\n"', that output shows up immediately on the console because stderr is not buffered (stdout is). Alternatively, you can call flush() on a filehandle to flush the buffers.

But for console commands that take awhile, consider just printing the status to STDERR instead of the default print of STDOUT. Of course there are some "yeah, but's" with that which are application specific.

I do congratulate you on the idea of presenting an indication of progress that actually means something! I hate this Windows graphic like when you copy files...it is a separate doo-dad that has nothing at all do with any "real" progress - the real program can hang and that thing merrily goes along with its graphical fake out.

If you wind up calling some progress bar graphical thing, be aware that graphical output is "expensive" CPU wise. Call it only when necessary (ie you expect that the progress bar will actually move on the screen).

As another point, the first time I saw this in Windows, I was really surprised because I was used to O/S'es that printed to the console so fast that you could hardly tell that it happened! But Windows is slow when it prints to the console. I don't know why that is. But that appears to be the case. And sometimes the program speeds up quite a bit when you print less.


In reply to Re: Real Time Progress Bar in console by Marshall
in thread Real Time Progress Bar in console by westrock2000

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.