How to answer to prompts automatically with python fabric?

后端 未结 6 1247
一个人的身影
一个人的身影 2020-11-29 23:42

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

6条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-30 00:22

    Starting from version 1.9, Fabric includes a way of managing this properly.

    The section about Prompts in the Fabric documentation says:

    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.

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

提交回复
热议问题