【发布时间】:2012-02-13 13:22:03
【问题描述】:
我已经按照这里的步骤http://jessenoller.com/2009/02/05/ssh-programming-with-paramiko-completely-different/
通过 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,它似乎工作正常。如果我在服务器上输入“which php”,我会被告知它所在的位置,而不是上面的错误消息。我发送了一些其他命令来故意获取错误消息,以查看它是否清除了任何内容。相反,它在最后添加了一些东西。
根据错误消息,我去查看了引用的 drush 文件。这是第 89 行:
exec "$php" $php_options "$SCRIPT_PATH" --php="$php" --php-options="$php_options" "$@"
我相信“which 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 命令可以正常工作。
【问题讨论】:
标签: python drupal unix paramiko drush