Took a while but i could figure it out. Just in case any one is interested.
==== skipped the tn connect part===
Prompt capture to a string:
==== skipped the tn connect part===
Prompt capture to a string:
>>>tn.write(b" " + "\n".encode('ascii')) ===> Send a simple enter("\n" character and capture the output to get prompt. >>>str2 = tn.read_eager().decode() ====> Save prompt to a string. >>>print(str2)
Output:[Router]R5-NYC#
Command output capture to a string in case output is multiple lines.>>>tn.write(b"show clock" + "\n".encode('ascii')) >>>str2 = tn.read_very_eager().decode() >>>print(str2)
Output:show clock
Wed May 22 07:16:09 2019 CST
[Router]R5-NYC#
tn.read_eager()
===> Kinda returns line by line output but very inconsistent and can be saved to a string. tn.read_very_eager()
=== > Returned the entire output(including multiple lines) and can be saved to a string.