2013-06-30 143 views
2

新代碼:PHP SVN更新 - TortoiseSVN的

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

這將導致一個無限循環,沒有返回結果。我究竟做錯了什麼?

== ==編輯

在Windows上,我試圖更新使用PHP的項目。我在使用命令行時遇到問題:我需要視覺反饋(在發生衝突時很重要),所以我不想以後臺進程開始。這可能嗎?

我到目前爲止的代碼是:

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

也許你應該先看看這個呢? http://php.net/manual/en/book.svn.php – tlenss

+0

沒有針對Windows預編譯php_svn.dll。我沒有這方面的知識。 – Simon

+3

您正在使用錯誤的工具進行這項工作。 'TortoiseProc.exe'不能用於非GUI /非交互模式的其他軟件。 @tlenss指出你的方向正確,或者你可以使用[phpsvnclient](https://code.google.com/p/phpsvnclient/),或者真正的命令行客戶端('svn.exe') TortoiseSVN自1.7)。 – alroc

回答

3

我會放棄EXEC和使用proc_open(見http://php.net/manual/en/function.proc-open.php

這裏是我迅速掀起了一個例子,它應該工作你:

<?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); 

?> 
+0

爲什麼proc_open更好?我讀過它有很大的缺點 – Simon