title: Execute a CLI command and store in a variable using telnetlib
body: <p>I am using Python telnetlib for taking the "running config" output from router.How to store the "show running-config" output in a variable.And print the variable.My requirement is the each and every output will display in the console when executing each and every line of the code.Is there any option to aviod these print statements.</p>
  
  <pre><code>import telnetlib
  #import getpass
  ipaddr = "10.1.1.1"
  passwd = "abcd123"
  tn = telnetlib.Telnet(ipaddr)
  if Password:
      try:
            print (tn.write (password + "\n"))
            print(tn.read_until("Router&gt;"))
            print(tn.write("enable\n"))
            print(tn.read_until("Password:"))
            print(tn.write(passwd + "\n"))
            print(tn.read_until("Router#"))
            print(tn.write("show clock\n"))
            print(tn.read_until("#"))
            print(tn.write("show running-config\n"))
            print(tn.write("\040\n"))
            print(tn.write("\040\n"))
            print(tn.write("\040\n"))
            print(tn.read_until("#"))
            print(tn.write("logout\n"))
            print(tn.read_until("&gt;"))
            print tn.close
  </code></pre>