Update command line output

前端 未结 5 1951
逝去的感伤
逝去的感伤 2021-02-05 21:33

My program (which happens to be in Perl, though I don\'t think this question is Perl-specific) outputs status messages at one point in the program of the form Progress: x/

5条回答
  •  灰色年华
    2021-02-05 22:22

    Say

    $| = 1
    

    somewhere early in your program to turn autoflushing on for the output buffer.

    Also consider using "\r" to move the cursor back to the beginning of the line, rather than trying to explicitly count how many spaces you need to move back.

    Like you said, don't print out a newline while your progress counter is running or else you will print out your progress on a separate line instead of overwriting the old line.

提交回复
热议问题