duandian4501 2017-01-02 02:18
浏览 46
已采纳

来自PHP脚本的CMD - 获得反馈

I have a LOT ( almost 300 ) old SVN repositories to migrate to git using git2svn.

After considering GOLANG and PYTHON, I finally decided that the easiest way is to use PHP . Might be a bad questionable decision, but it's seemed easy.

So, after 15 minutes , I did have a script that is more or less running ok in tests . Ugly script , but it is a one-timer.

The problem is that the process takes a lot of time , even for simple almost empty repos is can take 30sec. and even a minute. On big ones - even 10min - so before taking it into production, I would like to have some feedback mechanism - so I can actually see what is going on .

..as of now ,the script does output the command feedback like so :

$cmd = "cd ".$GITrepoPath." && svn2git svn://127.0.0.1/". $repoName . " --username " .$SVNusername ." --authors authors.txt --notags --nobranches --notrunk";
            $output = shell_exec($cmd);
            echo "<pre>$output</pre>";

..but this is only after each repo was finished processing .. not like the real cmd execution where I can see the steps .

The only question I found that might be close to what I need was here - but honestly - I did not understood much from the answer ...

I know it is just a one-timer script - but the use case had me interested in how to actually achieve that ( and if it is possible ).

I am on a win7 local machine , but would like to know also for *nix if possible .

  • 写回答

2条回答 默认 最新

  • dongzhan8001 2017-01-02 04:00
    关注

    shell_exec waits until the process closes. You have to create the process and listen to it, the same as CMD. Use exec function in this way:

    $cmd = ''; // your command here
    $output_storage = [];
    $output_showed = [];
    $result = null;
    exec($cmd, $output_storage, $result);
    while( $result === null ){
        $diff = array_diff($output_storage, $output_showed);
        if( $diff ){
            // all new outputs here as $diff
            $output_showed = $diff;
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 蓝桥oj3931,请问我错在哪里
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染