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

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

问题描述

我已按照此处的步骤操作 http://jessenoller.com/2009/02/05/ssh-programming-with-paramiko-completely-different/

通过 Python 使用 ssh 连接到我的服务器.我可以正常连接并发送命令.

然而,当我运行 stderr.readlines() 时,它每次都会向我显示以下错误消息,即使该命令似乎已正确执行.我已经关闭了连接并重新启动了 Python,结果还是一样.

这是一个 Python 示例:

<预><代码>>>>标准输入,标准输出,标准错误 = myssh.exec_command("xyz")>>>stderr.readlines()['which: no php in (/usr/bin:/bin:/usr/sbin:/sbin:/big/dom/mydomain/pear/drush) ', '/big/dom/mydomain/pear/drush/drush: line 89: exec: : not found ', 'bash: xyz: command not found ']

我已经安装了 drush,它似乎工作正常.如果我在服务器上输入which php",我会被告知它所在的位置,而不是上面的错误消息.我发送了一些其他命令来故意获取错误消息以查看它是否清除了任何内容.相反,它在最后添加了一些东西.

根据错误消息,我去查看引用的 drush 文件.这是第 89 行:

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

我相信which php"命令来自此行上方块中的 $php 变量

if [ !-z "$DRUSH_PHP" ] ;然后# 如果可用,请使用 DRUSH_PHP 环境变量.php="$DRUSH_PHP"别的# 默认使用我们在 PATH 中找到的 php.# 请注意,我们需要在这里为 Dreamhost 提供 php 的完整路径,它的行为很奇怪.见 http://drupal.org/node/662926php=`哪个php`# 我们检查命令行 (cli) 版本的 php,如果找到就使用它.which php-cli >/dev/null 2>&1如果 [ "$?"= 0];然后php=`哪个 php-cli`菲# 在 MSYSGIT 上,我们需要使用php",而不是 php 的完整路径如果 [ !-z "$MSYSTEM" ] &&[ "x${MSYSTEM:0:5}" = "xMINGW"] ;然后php="php"菲菲

文件全文在这里:http://pastebin.com/29AXmHKF

如果我尝试执行任何 drush 命令,我会遇到同样的错误.但是,如果我直接使用 python/paramiko 将自己登录到服务器,则 d​​rush 命令可以正常工作.

解决方案

我使用了 Mike Ryan 的解决方案(感谢 Mike!)但在 stdout 中找到了信息,而不是 stderr.

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

I've followed the steps here http://jessenoller.com/2009/02/05/ssh-programming-with-paramiko-completely-different/

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

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.

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)
', '/big/dom/mydomain/pear/drush/drush: line 89: exec: : not found
', 'bash: xyz: command not found
']

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.

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" "$@"

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

The full text of the file is here: http://pastebin.com/29AXmHKF

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.

解决方案

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天全站免登陆