doudaochu1699
2013-06-30 08:32 阅读 90

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 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.

    点赞 7 评论 复制链接分享

相关推荐