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条)

报告相同问题?

悬赏问题

  • ¥100 高价邀请复制 域天d8联网狗
  • ¥15 本题的答案是不是有问题
  • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?