我跟着步驟這裏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