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

报告相同问题?

悬赏问题

  • ¥30 Hyper-v虚拟机相关问题,求解答。
  • ¥15 TSM320F2808PZA芯片 Bootloader
  • ¥30 谷歌浏览器出现开发者工具无法显示已创建的,但您可以调试已部署的代码。 状态代码 404, net::ERR HTTP RESPONSE CODE FAILURE
  • ¥15 chatgpt网页版侧边栏和模型切换点击没反应怎么办
  • ¥15 dev运行环境,c语言,报错是为什么?怎么改
  • ¥15 如何解决蓝牙通话音频突发失真问题
  • ¥15 安装opengauss数据库报错
  • ¥15 【急】在线问答CNC雕刻机的电子电路与编程
  • ¥60 在mc68335芯片上移植ucos ii 的成功工程文件
  • ¥15 笔记本外接显示器正常,但是笔记本屏幕黑屏