使用exec、shell_exec或system从PHP运行SVN命令


Running SVN commands from PHP using exec, shell_exec, or system

我有一段非常简单的代码,理论上应该可以从php中获得svn列表

<?php
print_r("Method 1<br/>");
$x = exec("/usr/bin/svn list svn+ssh://svn.server.com/path/to/trunk/ 2>&1", $o, $m);
print_r($o);
print_r("<br/><br/><br/>");
print_r("Method 2<br/>");
$x = exec("/usr/bin/svn list --username user --password pass svn+ssh://svn.server.com/path/to/trunk/ 2>&1", $o, $m);
print_r($o);
?>

这两种方法都返回以下错误

Method 1
Array ( [0] => svn: warning: Can't open file '/root/.subversion/servers': Permission denied [1] => No protocol specified [2] => [3] => (gnome-ssh-askpass:6062): Gtk-WARNING **: cannot open display: :0.0 [4] => svn: To better debug SSH connection problems, remove the -q option from 'ssh' in the [tunnels] section of your Subversion configuration file. [5] => svn: Network connection closed unexpectedly ) 

Method 2
Array ( [0] => svn: warning: Can't open file '/root/.subversion/servers': Permission denied [1] => No protocol specified [2] => [3] => (gnome-ssh-askpass:6062): Gtk-WARNING **: cannot open display: :0.0 [4] => svn: To better debug SSH connection problems, remove the -q option from 'ssh' in the [tunnels] section of your Subversion configuration file. [5] => svn: Network connection closed unexpectedly [6] => svn: warning: Can't open file '/root/.subversion/servers': Permission denied [7] => No protocol specified [8] => [9] => (gnome-ssh-askpass:6066): Gtk-WARNING **: cannot open display: :0.0 [10] => svn: To better debug SSH connection problems, remove the -q option from 'ssh' in the [tunnels] section of your Subversion configuration file. [11] => svn: Network connection closed unexpectedly )

我可以很好地从命令行运行任何一个svn命令,我也有基于ssh密钥的身份验证设置,可以与svn.server.com 对话

我所想做的就是从主干中获取文件夹列表。我们的svn只是为svn+ssh访问设置的。

有什么想法吗?

您的答案在这里:

通过浏览器从php脚本调用svn更新不起作用

  1. 在.svn目录上运行chmod 777
  2. 通过命令行运行svn更新
  3. 调用脚本