Hi, If any is familiar with pexpect, please help to point out why my script seems to fail to capture the desired text.
Here, I want to log into a server 172.27.161.19. Once I see "Username: ", I will type in my userid "admin". The problem here is I have a list of keywords for pexpect to match before returning the matched item for me. The list consists of following list items: expects = ['yes', '.*Username: ', '.*login: |.*Login: ', 'SY-FAR-1>', 'SY-FAR-1#', 'Password: |password: ', '.*Press RETURN to get started'] Here, it seems my script found "Username: " but it got displayed as PART OF _pexpect_session.after (and this is what I don't understand). The ".before" or ".after" data should consist of match before and after the desired keyword only. ============= Manual Execution ======================= telnet 172.27.161.19 Trying 172.27.161.19... Connected to 172.27.161.19. Escape character is '^]'. User Access Verification Username: admin Password: SY-FAR-1>en SY-FAR-1# =============== Python Script Snippet ======================= expects = ['yes', '.*Username: ', '.*login: |.*Login: ', 'SY-FAR-1>', 'SY-FAR-1#', 'Password: |password: ', '.*Press RETURN to get started'] i = -1 # reset its value print "*step 1*before match, i = %s" % i self._pexpect_session.timeout = 80 cmd = "admin" self._log("Executing CLI: '{0}'".format(cmd)) self._pexpect_session.sendline(cmd) i = self._pexpect_session.expect(expects) print "*step 2* found index i = %s" % i print "*step 3* after match, exec_cmd expects (%s) =" % i, expects print "*step 4* exec_cmd match before: '%s'" % self._pexpect_session.before print "*step 5* exec_cmd match after: '%s'" % self._pexpect_session.after =============== Actual Script Output ====================== *step1* before match, i = -1 Executing CLI: 'admin' *step2* found index i = 1 *step3* after match, exec_cmd expects (1) = ['yes', '.*Username: ', '.*login: |.*Login: ', 'SY-FAR-1>', 'SY-FAR-1#', 'Password: |password: ', '.*Press RETURN to get started'] *step4* exec_cmd match before: '' *step5* exec_cmd match after: ' Username: ' Appreciate any input or explanation. Thanks, Viet -- https://mail.python.org/mailman/listinfo/python-list