PHP:exec(svn commit)不会返回任何错误,也无法正常工作 [英] PHP: exec(svn commit) is not returning any errors nor working

查看:93
本文介绍了PHP:exec(svn commit)不会返回任何错误,也无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,我正在用php将文件写到目录中,我将该目录添加(工作正常),然后当我尝试执行svn时,提交它不起作用,也不返回任何错误代码.有人对此有任何想法吗?

Currently I'm writing out files with php into a directory, I add that directory (works fine), then when i try and do an svn commit its not working nor returning any kind of error codes. Does anyone have any idea on this?

$tmp = exec('cd '.$this->build_locations[$this->type].'; svn commit --username user --password pw; ls', $output);

我将CD转到目录(此处的ls工作正常),然后再执行ls确认其仍在目录中.

I do the cd to the directory (did ls in here worked fine), I do an ls afterwards to confirm its still in the directory.

我也尝试过:

svn help

这使我所有的命令都恢复正常(因此我知道没有找到svn命令不是问题.

which returns me all the commands just fine (so i know its not an issue with not finding the svn command.

我已将文件777更改为可以执行的文件.

I've chmoded the file 777 to confirm it can execute.

修改后的代码:

    $output = array();
    $tmp1 = exec("cd ".$this->build_locations[$this->type].";");
    $tmp = exec("svn commit ".$this->build_locations[$this->type].$this->app_id." --username user --password password -m 'test' --non-interactive --trust-server-cert --quiet 2>&1;", $output, $error);
    if($error){
        echo('<pre>');
        print_r($output);
        echo('</pre>');
    }
    exit;

这将产生:

Array

    [0] => could not lookup DNS configuration info service: (ipc/send) invalid destination port
    [1] => svn: Commit failed (details follow):
    [2] => svn: Unknown hostname 'my.host'

推荐答案

SVN命令行错误出现在stderr而不是stdout上,这就是为什么您看不到它们的原因.您要执行的操作是将stderr重定向到stdout,然后再print_r($output)确定错误原因.

SVN command line errors go to stderr, not stdout, which is why you aren't able to see them. What you want to do is redirect stderr to stdout and then print_r($output) to determine the cause of the error.

exec('svn commit <stuff> 2>&1', $output, $returnStatus);
if ( $returnStatus )
{
    print_r($output);
}

示例输出:

Array
(
    [0] => svn: Commit failed (details follow):
    [1] => svn: '/path/to/<stuff>' is not under version control
)

这是不理想的,因为在本来没有必要的情况下,它将stderr与stdout混合在一起,但是在这种情况下,我不知道另一种获得所需输出的方法.如果有人这样做,请发表评论.

This is not ideal because it mixes stderr with stdout when it would otherwise be unnecessary, but I don't know of another way to get the desired output in this case. If someone else does, please comment.

注意: exec( ...)是返回状态状态,而不是错误消息,因此您也需要相应地调整代码.

Note: The third parameter to exec(...) is the return status, not the error message, so you need to tweak your code accordingly for that as well.

如果进行2>&1修改后的错误输出不能帮助解决问题的根本原因,请在此处发布新的输出.

If the error output after making the 2>&1 modification doesn't help solve the root cause of your problem, please post the new output here.

在新信息后

您是否已将此SVN工作副本从其他地方上传到您的服务器?那可以解释这个错误.

Did you upload this SVN working copy to your server from somewhere else? That would explain this error.

如果我从本地存储库中签出工作副本,将其上传到远程服务器,然后尝试提交,则会遇到相同的错误.

If I check out a working copy from my local repository, upload it to my remote server, and then try to commit, I get the same error.

在这种情况下,您需要在运行PHP脚本的服务器上执行工作副本的"svn签出" ,以便能够对其进行提交.如果该服务器无法与存储库的服务器通信,那将是另一个问题.

If that's the case, you need to execute the "svn checkout" of the working copy on the server running the PHP script in order to be able to commit to it. If that server can't communicate with the repository's server, then that's a whole other problem.

这篇关于PHP:exec(svn commit)不会返回任何错误,也无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆