我跟着步骤这里http://jessenoller.com/2009/02/05/ssh-programming-with-paramiko-completely-different/Drush命令不执行使用的paramiko
通过Python用ssh连接到我的服务器。我可以很好地连接并发送命令。
但是,当我运行stderr.readlines()时,即使该命令似乎已正确执行,它也会在每次显示下面的错误消息。我关闭了连接并重新启动了Python,结果仍然相同。
下面是一个Python示例:
>>> stdin, stdout, stderr = myssh.exec_command("xyz")
>>> stderr.readlines()
['which: no php in (/usr/bin:/bin:/usr/sbin:/sbin:/big/dom/mydomain/pear/drush)\n', '/big/dom/mydomain/pear/drush/drush: line 89: exec: : not found\n', 'bash: xyz: command not found\n']
我已经drush安装,它似乎很好地工作。如果我在服务器上输入“哪个php”,我会告诉它它驻留的位置,而不是上面的错误信息。我发送了一些其他命令来有目的地得到错误信息,看看它是否清除了任何东西。相反,它在最后加上了一些东西。
错误消息后,我去看了看引用的drush文件。这里的线89:
exec "$php" $php_options "$SCRIPT_PATH" --php="$php" --php-options="$php_options" "[email protected]"
我相信“的PHP”命令来自$ PHP变量在块上面这条线
if [ ! -z "$DRUSH_PHP" ] ; then
# Use the DRUSH_PHP environment variable if it is available.
php="$DRUSH_PHP"
else
# Default to using the php that we find on the PATH.
# Note that we need the full path to php here for Dreamhost, which behaves oddly. See http://drupal.org/node/662926
php=`which php`
# We check for a command line (cli) version of php, and if found use that.
which php-cli >/dev/null 2>&1
if [ "$?" = 0 ] ; then
php=`which php-cli`
fi
# On MSYSGIT, we need to use "php", not the full path to php
if [ ! -z "$MSYSTEM" ] && [ "x${MSYSTEM:0:5}" = "xMINGW" ] ; then
php="php"
fi
fi
文件的全文在这里:http://pastebin.com/29AXmHKF
如果我尝试执行任何drush命令,我会得到相同的错误。但是如果我直接使用python/paramiko直接登录到服务器,drush命令可以正常工作。
如果我在服务器提示符下键入xyz,我会得到同样的错误消息,这个错误消息被粘贴到stderr上面。设置PATH可能与它有关。我在共享服务器上,所以我必须添加一行到.bashrc,以便将另一个目录添加到$ PATH。我会看一看,看看我做了什么。 – 2012-01-18 21:56:30