How to answer to prompts automatically with python fabric?

后端 未结 6 1249
一个人的身影
一个人的身影 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:28

    Note: this answer is several years old, and in the mean time fabric has (interestingly similar looking) implementation of this. See the answer by @timothée-jeannin below.

    See https://stackoverflow.com/a/10007635/708221

    pip install fexpect

    from ilogue.fexpect import expect, expecting, run 
    
    prompts = []
    prompts += expect('What is your name?','John')
    prompts += expect('Are you at stackoverflow?','Yes')
    
    with expecting(prompts):
        run('my_command')
    

    Fexpect adds answering to prompts to fabric with use of pexpect

提交回复
热议问题