PHP: exec(svn commit) is not returning any errors nor working
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);
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.
I've also tried:
svn help
which returns me all the commands just fine (so i know its not an issue with not finding the svn command.
I've chmoded the file 777 to confirm it can execute.
Edited Code:
$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);
i开发者_JS百科f($error){
echo('<pre>');
print_r($output);
echo('</pre>');
}
exit;
This produces:
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 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);
}
Sample output:
Array
(
[0] => svn: Commit failed (details follow):
[1] => svn: '/path/to/<stuff>' is not under version control
)
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.
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.
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.
Edit after new information:
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.
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.
Can you try throwing out the errors (read Mike's comment) status.
('cd '.$this->build_locations[$this->type].'; svn commit --username user --password pw; ls', $output, $error);
if($error){
print_r($error);
}
I would suggest to break the above into 3 separate commands for debugging purpose.
Also, if $this-type can be manipulated by the users, then your code is vulnerable as they can pass something like: .; cat /etc/passwd
, which becomes
$tmp = exec('cd .; cat /etc/passwd; svn commit --username user --password pw; ls', $output);
AFAIK, after a svn commit
, if the -m
option is not provided, an editor opens up to type in the commit message. Try passing -m "Some commit message"
, maybe that'll help.
精彩评论