UPDATE! The community will be go into read-only on April 19, 8am Pacific in preparation for migration on April 21. Read more.
UPDATE! The community will be go into read-only on April 19, 8am Pacific in preparation for migration on April 21.Read more.

pexpect child.before empty for commands executed after connect device

Hi all,

I am trying to code a script which will login into HPNA then connect to a device and execute a command and receive the output. Like
Using Python pexpect. Steps inside script I am following is 

1. Using pexpect connect to NA Proxy

2. Execute "Connect <device_ip>"

3. On connected device , execute "show version"

4. Get "show version" output to a variable, using "child.before"

Everything works fine except #4. I am getting nothing as show version output.

But If use same env and script to login/ssh directly  to device and execute the "show version" I get output to my variable child.before.
Also if using script, I login into NA Proxy and execute any local command (for ex : show task) I see child.before output.

Only when script login to NA proxy and then connect to another device and execute command, command output or child.before is blank.

Can someone please help .

 --------------------------- Python Script ~~~~~~~~~~~~~~~~~~~~~~~~

# Connecting to HP NA cli

child = pexpect.spawn('ssh -l %s %s -p %s %s' %(HostTacUser,HostName,ssh_port,SSH_OPTIONS))
child.delaybeforesend = 0.05
child.expect('assword:', timeout=20)


child.expect ('NA>')
logfile_prefix = str(time.time());
logfile = "/tmp/ACI_BUG_CHECK_"+logfile_prefix
print "Log File : %s" % logfile
child.logfile = open(logfile, "w")

#Connecting to a Cisco device from HP NA cli


index = child.expect (["[a-z|A-Z|0-9|\-]{3,30}>","]#",pexpect.EOF, pexpect.TIMEOUT], timeout=20)

child.sendline('show version')
index = child.expect (["[a-z|A-Z|0-9|\-]{3,30}>","]#",pexpect.EOF, pexpect.TIMEOUT], timeout=20)

show_out = []
if index == 0:
show_out = child.before.splitlines()


but show_out doesnt contain any output



Labels (1)
1 Reply
Fleet Admiral
Fleet Admiral

Hi @Bobin Thomas,

you can set api and feature/proxy in trace on the web ui to see on the log files what is the interacction with NA proxy and the device.

btw, it seems this thread is duplicated, or I have the wrong impresion?

Pedro A. Batista
Customer Support Engineer

If you find that this or any other post resolves your issue, please be sure to mark it as an accepted solution.
If you are satisfied with anyone’s response please remember to give them a KUDOS by clicking on the THUMB at the bottom left of the post and show your appreciation.
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.