michaelye1988
V2EX  ›  问与答

php如何在shell里面显示当前执行的进度?

  •  
  •   michaelye1988 · Dec 25, 2013 · 2806 views
    This topic created in 4613 days ago, the information mentioned may be changed or developed.
    function test()
    {
    for($i = 0; $i < 100; $i++)
    {
    echo($i."%100\n");
    }
    }

    上面的代码实现的效果如图:


    不是我想要的效果,请问如何直接在单行显示和更新当前的进度,这在shell里面是否可行?
    1 replies    1970-01-01 08:00:00 +08:00
    michaelye1988
        1
    michaelye1988  
    OP
       Dec 25, 2013
    已解决:

    function test()
    {
    for($i = 0; $i < 100; $i++)
    {
    // echo($i."%100\n");
    echo($i."%100\r");
    sleep(1);
    }

    }

    把"\n"换成"\r"即可,就是这么简单!

    感谢stackoverflow
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1366 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 18ms · UTC 23:56 · PVG 07:56 · LAX 16:56 · JFK 19:56
    ♥ Do have faith in what you're doing.