如何让 Fabric 自动(而不是用户交互)与 shell 命令交互?与 pexpect 结合? [英] How to get Fabric to automatically (instead of user-interactively) interact with shell commands? Combine with pexpect?

查看:22
本文介绍了如何让 Fabric 自动(而不是用户交互)与 shell 命令交互?与 pexpect 结合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

寻求手段让 Fabric 自动(而不是用户交互地)与 shell 命令(而不仅仅是请求)交互用于密码,但在没有像 apt-get install -y 这样的标准输入/交互式覆盖"可用时也要求用户输入).

Seeking means to get Fabric to automatically (instead of user-interactively) interact with shell commands (and not just requests for passwords, but also requested user input when no "stdin/interactive override" like apt-get install -y is available).

这个问题以及这些Fabric 文档 建议 Fabric 只能推动交互性"返回给运行 Fabric 程序的人类用户.寻求在没有任何人存在的情况下完全自动化.目前还没有一个真正的"要解决的问题,只是为可能的、未来的障碍做准备.

This question along with these Fabric docs suggest that Fabric can only "push the interactivity" back to the human user that's running the Fabric program. Seeking to instead fully automate without any human presence. Don't yet have a "real," current problem to solve, just preparing for possible, future obstacle.

如果 Fabric 可以,与 pexpect(或类似的替代机制)结合使用可能很有用不是专门自动处理所有标准输入/提示吗?希望它不需要是非此即彼".如果适用,为什么不在同一个程序/自动化中同时利用两者(pexpect 和 Fabric)?

Possibly useful to combine with pexpect (or similar, alternative mechanism) if Fabric can't exclusively handle all stdin/prompts automatically? Hoping it doesn't need to be an "either/or" kind of thing. Why not leverage both (pexpect and Fabric) where appropriate, if applicable, in same program/automation?

推荐答案

作为 Glenn,我会说使用 pexpect;此外,

As Glenn, I would say use pexpect; in addition,

看看我写的这个包装器来编写织物的预期行为:

have a look at this wrapper I wrote to script the pexpect behaviour from fabric:

from ilogue.fexpect import expect, expecting, run 

prompts = []
prompts += expect('What is your name?','John')
prompts += expect('Where do you live?','New York')

with expecting(prompts):
    run('command')

另见我关于 fexpect 或如何处理提示的博文在面料与 pexpect

这篇关于如何让 Fabric 自动(而不是用户交互)与 shell 命令交互?与 pexpect 结合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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