views:

561

answers:

3

I would like to automate the response for some question prompted by some programs, like mysql prompting for a password, or apt asking for a 'yes' or ... when I want to rebuild my haystack index with a ./manage.py rebuild_index.

For MySQL, I can use the --password= switch, and I'm sure that apt has a 'quiet' like option. But how can I pass the response to other programs ?

+2  A: 

Why can't you just use pipes?

For example, for an automated auto accept, just use yes, that just outputs a neverending stream of y.

yes | rm *.txt

voyager
+2  A: 

If you are looking for a user to confirm an operation, use the confrim method.

if fabric.contrib.console.confirm("You tests failed do you want to continue?"):
  #continue processing

Or if you are looking for a way to get input from the user, use the prompt method.

password = fabric.operations.prompt("What is your password?")
mountainswhim
Instead of using Fabric's prompt for a password, I would recommend importing getpass and using that so that you don't display the password on the terminal as it's being typed. For non-password input, then I agree that Fabric's prompt is good to use.
Matthew Rankin
A: 
dzen