Drush命令不使用Paramiko执行 [英] Drush commands not executing using Paramiko

查看:191
本文介绍了Drush命令不使用Paramiko执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已按照这些步骤 http: //jessenoller.com/2009/02/05/ssh-programming-with-paramiko-completely-different/

使用ssh连接到我的服务器通过Python。我可以连接罚款和发送命令。

to connect to my server with ssh via Python. I can connect fine and send commands.

然而,当我运行stderr.readlines()时,它每次都会显示错误消息,即使命令似乎已经执行正确。我已经关闭了连接并重新启动了Python,并且仍然是相同的结果。

When I run stderr.readlines(), however, it shows me the error message below every time, even if the command seems to have executed correctly. I've closed the connection and restarted Python, and still the same result.

这是一个Python示例:

Here's a Python sample:

>>> 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,我被告知它驻留在哪里,而不是上面的错误消息。我发送了一些其他命令,目的是得到一个错误消息,看看它是否清除任何东西。相反,它结束了事情。

I have drush installed and it seems to work fine. If I type in "which php" on the server I'm told where it resides, instead of the error message above. I sent some other commands to purposefully get an error message to see if it cleared anything out. Instead it tacked things on at the end.

跟随错误消息,我去看了引用的drush文件。这是第89行:

Following the error message, I went and looked at the drush file referenced. Here's line 89:

exec "$php" $php_options "$SCRIPT_PATH" --php="$php" --php-options="$php_options" "$@"

我相信哪个php命令来自$ php变量在该行上方的块

I believe the "which php" command comes from the $php variable in the chunk above this line

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命令可以正常工作。

I get the same error if I try to execute any drush command. But drush commands work fine if I just log myself into the server directly w/o using python/paramiko.

推荐答案

Ryan的解决方案(谢谢Mike!),但是发现stdout中的信息不是stderr。

I used Mike Ryan's solution (thanks Mike!) but found the information in stdout, not stderr.

stdin, stdout, stderr = server.ssh_client.exec_command("echo $PATH")
print stdout.readlines()

这篇关于Drush命令不使用Paramiko执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆