Alex Rivera | Logout

Python Fabric: How to handle arbitrary remote shell prompt for input?

Asked 2010-04-16T02:32:03.480
13

This is related to this question here, but with a slight twist: instead of just passing 'yes' or 'no', I need Fabric to pass an arbitrary string to the remote shell.

For instance, if the remote shell prompts for 'what is your name?' then I need to feed it 'first,last'.

Clarification: I know I said arbitrary input, but I was really trying to use it for the SSH key passwd prompt when I try to do a git pull.

Update #1: Got a response from Jeff Forcier @bitprophet

Edit
Report

1 Answer

5

I have proposed an API for this feature in fabric on the mailinglist, and ended up writing something myself:

from 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 my blogpost on expecting prompts in fabric with fexpect

answered 2012-03-08T08:48:02.603

Your Answer