python Fabric不允许我将输出通过管道传输到less?

发布于 2024-11-28 12:10:53 字数 488 浏览 1 评论 0原文

我是第一次设置 Fabric,但在将 Fabric 的输出传输到 less 时遇到了麻烦。例如,如果我运行:(

fabric deploy |less

其中,deploy 是我的部署函数)

我会从 Fabric 收到以下错误:

IOError: [Errno 22] Invalid argument

This comes from a run() command on the Remote Host。

如果我将 pty=False 添加到 run() 参数中,它就会起作用。然而,这意味着每个运行命令,我都需要添加这个参数。更不用说,我相信它对提示和输入数据有影响(显然对于这些情况我不会减少)。

我该如何解决这个问题?我应该对所有事情都执行 tty=false 吗?

I'm setting up fabric for the first time, and having trouble piping the output from fabric to less. For example, if I run:

fabric deploy |less

(Where deploy is my deployment function)

I get the following error back from fabric:

IOError: [Errno 22] Invalid argument

This comes from a run() command on the remote host.

If I add pty=False to the run() arguments, it works. However, that means every run command, I need to add this argument. Not to mention, I believe it has implications with prompts and entering data (obviously for those cases I won't be piping to less).

How can I fix this? Should I just do tty=false for everything?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花之痕靓丽 2024-12-05 12:10:53

仅供将来参考,我通过对 Operations.py 应用补丁解决了这个问题,如下所示:

http://code.fabfile.org/attachments/56/operations.patch

否则,重现此问题的代码如下:

from __future__ import with_statement
from fabric.api import *
from fabric.contrib.console import confirm
import re
import sys

def test():
    run('ls')

如果执行以下命令,则会出现此问题:

fab -H myhost 测试 |less

希望这对某人有帮助...我仍然不明白为什么这么旧的错误仍然没有在最新版本的 Fabric 中得到修复。

-达斯汀

Just for future reference, I resolved this by applying a patch to operations.py, as seen here:

http://code.fabfile.org/attachments/56/operations.patch

Otherwise, the code that would reproduce this problem is as follows:

from __future__ import with_statement
from fabric.api import *
from fabric.contrib.console import confirm
import re
import sys

def test():
    run('ls')

And the issue would come up if you did the following command:

fab -H myhost test |less

Hope this helps someone... I still don't understand why a bug this old still hasn't been patched in the latest release of fabric.

-Dustin

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文