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

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

问题描述

寻求意味着自动(而不是用户交互式)使 Fabric 与shell命令进行交互(而不仅仅是请求密码,但是当没有 apt-get install -y 可以使用stdin / interactive override时,也请求用户输入。

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).

此问题以及这些<一个href =http://docs.fabfile.org/en/1.3.3/usage/interactivity.html?highlight=interactive =noreferrer> Fabric docs 表明,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.

可能与 pexpect (或类似的替代机制)如果Fabric不能自动处理所有stdin /提示?希望它不需要是或者某种事情。为什么在相同的程序/自动化中不适用(pexpect和Fabric)(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?

推荐答案

会说使用pexpect;另外,

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

看看我写的这个包装器,用于从面料中编写pexpect行为:

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')

另请参阅我的博客

See also my blogpost on fexpect or how to handle prompts in fabric with pexpect

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

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