通过php脚本执行popen()的功能。它出什么问题了

时间:2014-02-19 03:53:05

标签: php shell

如果代码是这样的,那就没关系

header("Cache-Control:no-cache,must-revalidate");
$handle = popen('svn --version','r'); 
$read = stream_get_contents($handle);
echo "<pre>";
printf($read);
echo "</pre>"; 
pclose($handle);

没关系。 输出:

svn, version 1.6.11 (r934486) compiled Apr 11 2013, 16:13:51

Copyright (C) 2000-2009 CollabNet. Subversion is open source software,
see http://subversion.tigris.org/ This product includes software
developed by CollabNet (http://www.Collab.Net/).

The following repository access (RA) modules are available:

ra_neon : Module for accessing a repository via WebDAV protocol using Neon.

handles 'http' scheme
handles 'https' scheme
ra_svn : Module for accessing a repository using the svn network protocol.

with Cyrus SASL authentication
handles 'svn' scheme
ra_local : Module for accessing a repository on local disk.

handles 'file' scheme

但是当我将第二行代码更改为:

$handle = popen('svn up --username zmk --password 123456 /home/wwwroot/test/','r');

它不起作用。什么都没输出 如果我在命令行上运行第二行,结果是这样的,没关系: At revision 17.
我知道问题是由linux的许可引起的。
谁有这方面的经验?
给我一个演示链接,提前谢谢。

2 个答案:

答案 0 :(得分:0)

我看到用户名参数拼写错误:userNMAe。可能是这个原因? 你可以尝试任何方式 popen(&#39; svn up --usernmae zmk --password 123456 / home / wwwroot / test / 2&gt;&amp; 1&#39;,&#39; r&#39;); 看错误

答案 1 :(得分:0)

我已将代码更改为:

error_reporting(E_ALL);
$handle = popen('svn up --username zmk --password 123456 /home/wwwroot/test/ 2>&1','r'); 
echo "'$handle'; " . gettype($handle) . "\n";
$read = fread($handle, 2096);
echo $read;
pclose($handle);

我是从@Max Yerissov和php手册中得到的 http://www.php.net/popen

在这种情况下,输出为:

'Resource id #1'; resource

-----------------------------------------------------------------------
ATTENTION!  Your password for authentication realm:

   <svn://XXX.XXX.XXX.XXX:3690> XXXXX-a464-4fc8-9f54-XXXXXX

can only be stored to disk unencrypted!  You are advised to configure
your system so that Subversion can store passwords encrypted, if
possible.  See the documentation for details.

You can avoid future appearances of this warning by setting the value
of the 'store-plaintext-passwords' option to either 'yes' or 'no' in
'/home/www/.subversion/servers'.
-----------------------------------------------------------------------

然后,我修改了/home/www/.subversion/servers,如下所示: https://wiki.lib.umn.edu/Subversion/ClientConfiguration.html

[global]
store-passwords = yes
store-plaintext-passwords = no

最重要的是我从php手册中复制了代码。所以我能抓住这个bug。

enter image description here