I am using pexpect (pexpect-2.3-6.el6.noarch) trying to get some output via pexpect.before. However, I am getting weird characters at the very beginning:
get
ESC[?1lcurrentZone = green
What I need to get is this:
get currentZone = green
I am also using setecho(False/True), but this does not help at all.
I was searching on the internet for some tips and did not find anything which would work for me.
Here is an example of my code - the interactive program I was to interact with via pexpect is call bwcli. Within it there is a tree-like structure with various branches and possibility to traverse it via kind of 'cd' command.
f = open("new_ns_results.txt", "w")
child = pexpect.spawn('bwcli',timeout=300,maxread=10000)
child.setecho(False)
child.expect('NS_CLI> ')
child.sendline('config set yesNoPromptEnabled false')
child.expect('NS_CLI> ')
child.sendline('config set continuePromptEnabled false')
child.expect('NS_CLI> ')
child.sendline('config set scriptEchoingEnabled false')
child.expect('NS_CLI> ')
child.sendline('login admin')
child.expect('Password: ')
child.sendline('some_password')
child.expect('NS_CLI> ')
print ("Now let\'s get to work...")
child.sendline('cd /NSDiagnostic/OverloadControls/CallpUtil')
child.expect('NS_CLI/NSDiagnostic/OverloadControls/CallpUtil> ')
child.sendline('get')
child.expect('NS_CLI/NSDiagnostic/OverloadControls/CallpUtil> ')
f.write("%s" % str(child.before))
child.setecho(True)
Thanks in advance for your time. I am thankful for this, really.