Command Line Progress Percent Display, no echo

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    #1

    Command Line Progress Percent Display, no echo

    I want to display the progress of a job (a cron job) in PHP.

    I can do an echo, but the result will look like this:

    1%2%3%4%

    How do you "backspace" and over-write the percentage with the new value.

    I don't know where to begin looking for this. What do you even call this to do a Google search?

    Dan
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    #2
    I found this:
    http://snippets.dzone. com/posts/show/3760

    How can i get that to work in PHP. shell_exec() ?

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      Just add a \r in front of you output. That should cause the echo to overwrite the previous line.
      Like:
      [code=php]
      <?php
      for($i = 0; $i < 100; $i++) {
      echo "\r$i% Completed...";
      usleep(200000);
      }
      ?>
      [/code]
      That is assuming you are displaying this in a Linux terminal?

      Comment

      • dlite922
        Recognized Expert Top Contributor
        • Dec 2007
        • 1586

        #4
        Originally posted by Atli
        Just add a \r in front of you output. That should cause the echo to overwrite the previous line.
        Like:
        [code=php]
        <?php
        for($i = 0; $i < 100; $i++) {
        echo "\r$i% Completed...";
        usleep(200000);
        }
        ?>
        [/code]
        That is assuming you are displaying this in a Linux terminal?
        Thanks, that was easy.

        yes of course Linux :D

        Comment

        Working...