question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Inconsistent output with write_channel and read_channel

See original GitHub issue

Thanks again for the help on https://github.com/ktbyers/netmiko/issues/1315

I am using write_channel and read_channel to parse the possible subcommands for all commands in a router.

I wrote this function below

def getCommandsList(input_cmd):
    res = []
    print('cmd = show {} ?'.format(input_cmd))
    net_connect.write_channel("show {} ?".format(input_cmd))
    time.sleep(0.5)
    output = net_connect.read_channel()
    output = output.split('\n')
    for i in range(len(output)):
        if i != 0 and i != len(output) - 1: # skip first and last since they are not commands
            line = output[i]
            line = line.lstrip()
            cmd, description = line.split(' ', 1)
            description = description.lstrip().replace('\r', '')
            print(cmd, description)
            res.append(str(cmd))
    return res

and for a single run, it works great.

Input: 'aaa' (show aaa ?)
Output: ['ikegroup', 'locald', 'login', 'password-policy', 'sync', 'task', 'taskgroup', 'trace', 'userdb', 'usergroup']

However, if I run it continuously, it gives me a weird output

Input: 'aaa ikegroup' (show aaa ikegroup)
Error:
Traceback (most recent call last):
  File "parse.py", line 50, in <module>
    print(getCommandsList('aaa ikegroup'))
  File "parse.py", line 35, in getCommandsList
    cmd, description = line.split(' ', 1)
ValueError: need more than 1 value to unpack

and when I print out the output, it gives me

[u'show aaa ikegroup ?\r', u'\r ^\r', u"% Invalid input detected at '^' marker.\r", u'RP/0/RP1/CPU0:FRETTA-1#show aaa show aaa ikegroup ']

So, it seems like the output is inconsistent.

I am trying to do it recursively, but if the output is inconsistent, it will be very hard to do it.

Any help?

===========MORE INFO================

I tried to do this just to see the pattern of output:

net_connect.write_channel("show {} ?".format('aaa'))
time.sleep(0.5)
output = net_connect.read_channel()
print(output)
print('-------------')
net_connect.write_channel("show {} ?".format('aaa'))
time.sleep(0.5)
output = net_connect.read_channel()
print(output)
print('-------------')
net_connect.write_channel("show {} ?".format('aaa'))
time.sleep(0.5)
output = net_connect.read_channel()
print(output)
print('-------------')

this shows

-bash-4.2# python parse2.py
show aaa ?
  ikegroup         Show local IKE group(s)
  locald           locald sub system(cisco-support)
  login            login sub system
  password-policy  Show all the password policies configured in the system
  sync             aaa_lib_sync sub system(cisco-support)
  task             Show task information
  taskgroup        Show all the local taskgroups configured in the system
  trace            Show trace data for AAA sub system
  userdb           Show all local users with the usergroups each belong to
  usergroup        Show all the local usergroups configured in the system
RP/0/RP1/CPU0:FRETTA-1#show aaa
-------------
show aaa ?
                                 ^
% Invalid input detected at '^' marker.
RP/0/RP1/CPU0:FRETTA-1#show aaa show aaa
-------------
show aaa ?
                                 ^
% Invalid input detected at '^' marker.
RP/0/RP1/CPU0:FRETTA-1#show aaa show aaa show aaa
-------------

So it seems like I need a way to completely clear my input when I use the next write_channel.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
whyjay17commented, Aug 2, 2019

@ktbyers Thanks again!

0reactions
ktbyerscommented, Aug 3, 2019

You will have to figure out what they translate to in terms of ASCII and then send that character code using write_channel.

Read more comments on GitHub >

github_iconTop Results From Across the Web

vdma write and read question - Xilinx Support
I don't know if the read channel faster than the write channel is related to my operation of reading files using AXI Stream...
Read more >
pynq.lib.video Module - Read the Docs
The driver is split into input and output channels are exposed using the readchannel and writechannel attributes. Each channel has start and stop...
Read more >
Display top 10 words in a CSV file - java - Stack Overflow
The way to calculate top 10 words in a CSV file depends on the size of the file. Small files (can be stored...
Read more >
Error using solve command, says input and output are ...
When I type in my code it tells me that an input of 2 variables and an output of 7 variables is inconsistent....
Read more >
Timing gradient smoothing circuit in a synchronous read channel
Smoothing the timing gradient reduces gain variations in the PLL and results in more effective timing recovery. Latest Cirrus Logic, Inc. Patents: Computing ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found