python - 如何使用 python fabric 自动回答提示?

标签 python command-prompt fabric

我想运行一个命令,提示我输入 yes/no 或 y/n 或其他。如果我只是运行命令 local("my_command") 然后它会停止并要求我输入。当我输入需要的内容时,脚本继续工作。如何自动响应提示?

最佳答案

1.9 版本开始,Fabric 包含了一种正确管理它的方法。

section about Prompts在 Fabric 文档中说:

The prompts dictionary allows users to control interactive prompts. If a key in the dictionary is found in a command’s standard output stream, Fabric will automatically answer with the corresponding dictionary value.

你应该可以让 Fabric 自动回答这样的提示:

with settings(prompts={'Do you want to continue [Y/n]? ': 'Y'}):
    run('apt-get update')
    run('apt-get upgrade')

关于python - 如何使用 python fabric 自动回答提示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10479078/

相关文章:

Python:使用下载的模块

command-line - 批量启动命令未打开程序

batch-file - 如何在批处理文件中运行多个命令?

python - 在 cronjob 上运行结构脚本

python - 如何让 matplotlib 打开用户评论框?

python - 在 Python 和 Perl 套接字之间交换数据

python - 当我尝试执行带有百分号的原始 SQL 字符串时,为什么 SQLAlchemy 会产生错误?

c# - 通过 C# 控制台应用程序运行批处理文件。命令被忽略

git - 我如何对项目的 cron 作业进行版本控制?

python - 如何让 Fabric 忽略 env.hosts 列表中的离线主机?