0

1.after executing expect('OPR>','show alef-users') it go to infinite means it run continuesly.

from fabric.api import *
from fabric.context_managers import settings
from ilogue.fexpect import expect, expecting, run

prompts = []
prompts += expect('Username:','kirti')
prompts += expect('Password:','kirti')
prompts += expect('OPR>','show users')
prompts +=expect('OPR>','exit')
env.password = "kirti@123"
with cd('/home/kirti/opr'):
with expecting(prompts):
run('./kirti', combine_stderr=False)
3
  • What's your current code? Commented Nov 23, 2017 at 6:23
  • when i run this code then it go in infinite means it go again an again expect('OPR>','show opr-users) it doesn't go to next expect('OPR>','exit') Commented Nov 23, 2017 at 9:07
  • You should simply add your code to the body of your question, via the edit link. It's hard to make heads or tales when it's this malformed. Commented Nov 23, 2017 at 9:08

1 Answer 1

1

Fabric >= 1.9 allows to handle multiple prompts at the same time, in a single with clause: you just have use Fabric's settings function, and feed it with a dict; the keys will be the questions, and the values will be the answers. In your case, it will look like :

with settings(prompts={'Username:':'admin', 
                       'Password:':'admin', 
                       'OPR>':'show alef-users', 
                       'OPR>':'exit'}):
    run('./go_opr_cli', combine_stderr=False)

My answer is inspired by that section of Fabric's official documentation. It worked very well for me, but make sure, when writing the dict's keys, that you respect the number of spaces between the last character of the question and the cursor, in the command line, otherwise it will fail.

Example: The last prompt is 'OPR>'. If you see in the regular Linux CLI, that there is one space between 'OPR>' and the cursor, then the key should be 'OPR> '

Sign up to request clarification or add additional context in comments.

2 Comments

small typo in your prompts dictionary, there should be a colon between the key and value
Two entries with the same key in the same dictionary? What is that supposed to mean? Only the last of these will actually exist in the dictionary.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.