Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 How to caputre an output of a CLI
#1
I need to capture an output of a CLI "show lic ?" in a variable or in buffer.

How to do it in python. I was using tcl where it has "receive_buffer" to capture it, not sure how to do it on python.

Please find the output below

Switch#show lic ?
comments Displays comments about the licenses.
feature-version Indicates the version of the feature that is using or can
use this license.
right-to-use Displays all the RTU licenses.
Quote
#2
Look at the Subprocess module.
metulburr likes this post
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Quote
#3
You can capture and store the output in a variable by pointing sys.stdout to the variable and executing your command.
eg->
o_variable = StringIO()      # variable to store stdout stream
sys.stdout = o_variable      # pointing stdout to variable
#Execute your commands
sys.stdout = sys.__stdout__  #restore std out
output = o_variable.getvalue()
print(output)

Quote

Top Page

Forum Jump:


Users browsing this thread: 1 Guest(s)