如何使用python fabric自动回答提示? [英] How to answer to prompts automatically with python fabric?
问题描述
我想运行一条命令,提示我输入yes / no或y / n或其他。如果我只运行命令 local( my_command)
,它将停止并要求我输入。当我键入所需的内容时,脚本将继续工作。如何自动响应提示?
I want to run a command which prompts me to enter yes/no or y/n or whatever. If I just run the command local("my_command")
then it stops and asks me for input. When I type what is needed, script continues to work. How can I automatically respond to the prompt?
推荐答案
从版本 1.9
,Fabric包含一种适当管理此问题的方法。
Starting from version 1.9
, Fabric includes a way of managing this properly.
关于提示的部分在Fabric文档中说:
The section about Prompts in the Fabric documentation says:
提示字典允许用户控制交互式提示。如果在命令的标准输出
流中找到字典中的
a键,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自动回答如下提示:
You should be able to make Fabric automatically answer prompts like this:
with settings(prompts={'Do you want to continue [Y/n]? ': 'Y'}):
run('apt-get update')
run('apt-get upgrade')
这篇关于如何使用python fabric自动回答提示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!