doudaochu1699 2013-06-30 08:32
浏览 95
已采纳

PHP SVN更新 - TortoiseSVN

New code:

<?php
exec('"C:\Program Files\TortoiseSVN\bin\svn.exe" update "c:\wamp\www\project"');

This results in an infinite loop, no result is returned. What am I doing wrong?

== edit ==

On Windows, I'm trying to update a project by using PHP. I'm having problems using the commandline: I want visual feedback (important in case of conflicts), so I don't want to start as a background process. Is this possible?

The code I have so far is:

<?php
$todo = "cd \"C:\\Program Files\\TortoiseSVN\\bin\\\"";
$todo2 = "START TortoiseProc.exe /command:update /path:\"C:\\wamp\\www\\project\\\" /closeonend:0";

 pclose(popen($todo, "r"));  
 pclose(popen($todo2, "r"));  
  • 写回答

1条回答 默认 最新

  • dongluzhi5208 2013-07-06 15:27
    关注

    I would drop exec and use proc_open (see http://php.net/manual/en/function.proc-open.php)

    Here's an example I quickly whipped up and which should work for you:

    <?php
    // setup pipes that you'll use
    $descriptorspec = array(
        0 => array("pipe", "r"),    // stdin
        1 => array("pipe", "w"),    // stdout
        2 => array("pipe", "w")     // stderr
    );
    
    // call your process
    $process = proc_open('"C:\Program Files\TortoiseSVN\bin\svn.exe" update "c:\wamp\www\project"',
                         $descriptorspec,
                         $pipes);
    
    // if process is called, pipe data to variables which can later be processed.
    if(is_resource($process)) 
    {
        $stdin = stream_get_contents($pipes[0]);
        $stdout = stream_get_contents($pipes[1]);
        $stderr = stream_get_contents($pipes[2]);
        fclose($pipes[0]);  
        fclose($pipes[1]);  
        fclose($pipes[2]);
        $return_value = proc_close($process);   
    }
    
    // Now it's up to you what you want to do with the data you've got.
    // Remember that this is merely an example, you'll probably want to 
    // modify the output handling to your own likings...
    
    header('Content-Type: text/plain; charset=UTF-8');  
    
    // check if there was an error, if not - dump the data
    if($return_value === -1)    
    {
        echo('The termination status of the process indicates an error.'."
    ");
    }
    
    echo('---------------------------------'."
    ".'STDIN contains:'."
    ");
    echo($stdin);
    echo('---------------------------------'."
    ".'STDOUTcontains:'."
    ");
    echo($stdout);
    echo('---------------------------------'."
    ".'STDERR contains:'."
    ");
    echo($stderr);
    
    ?>
    

    Aside:

    The line

    // call your process
    $process = proc_open('"C:\Program Files\TortoiseSVN\bin\svn.exe" update "c:\wamp\www\project"',
                         $descriptorspec,
                         $pipes);
    

    could also be escaped like this

    // call your process
    $process = proc_open("\"C:\\Program Files\\TortoiseSVN\\bin\\svn.exe\" update \"c:\\wamp\\www\\project\"",
                         $descriptorspec,
                         $pipes);
    

    which might or might not solve some problems on some systems that have hickups with the single brackets (') and spaces () in the notation.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 已有python代码,要求做成可执行程序,程序设计内容不多
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥15 小红薯封设备能解决的来
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助
  • ¥15 STM32控制MAX7219问题求解答
  • ¥20 在本地部署CHATRWKV时遇到了AttributeError: 'str' object has no attribute 'requires_grad'
  • ¥15 vue+element项目中多tag时,切换Tab时iframe套第三方html页面需要实现不刷新
  • ¥50 深度强化学习解决能源调度问题