PHP SVN update - TortoiseSVN

廉价感情. 提交于 2019-12-12 10:02:58

问题


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:


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.'."\r\n");
}

echo('---------------------------------'."\r\n".'STDIN contains:'."\r\n");
echo($stdin);
echo('---------------------------------'."\r\n".'STDOUTcontains:'."\r\n");
echo($stdout);
echo('---------------------------------'."\r\n".'STDERR contains:'."\r\n");
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.



来源:https://stackoverflow.com/questions/17388589/php-svn-update-tortoisesvn

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!