Python Forum
Exporting Python Output to Notepad
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Exporting Python Output to Notepad
#1
I have a txt file created named "commands.txt" and it contains muliple commands ( multiple lines)

sh run vlan 504
sh run vlan 505
sh run vlan 700
sh run vlan 708

I want to run this against two switches and want to keep the output of the commands in a notepad.Just the raw output.My current code is

def shvlan(device,child):
     vlans = []
     with open('commands.txt', 'r') as commands: 
         for command in commands:  
             child.sendline(command)  
             child.expect('.*#')  
             vlans.extend(child.after.splitlines())  

     child.close()  
     print device + ' conn closed'  
     print 'sh run vlan executed'  
     return vlans 
Any Suggestion how to do that ?
Reply
#2
One thing you can do is write the data to a file. There is a file tutorial in the tutorial section of this board.

Once you have the file, you can open it in Notepad manually, or you can open it with Python:

import os

with open('data.txt', 'w') as data_file:
    data_file.write('1 2 3 4')
os.startfile('data.txt')
As long as Notepad is the application associated with text files, this will open the file in Notepad.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020