【发布时间】:2017-10-30 20:49:12
【问题描述】:
问题:设备的输出未重定向到文件。 程序:根据我的程序,我已登录一台设备并尝试收集少量输出。这是程序。
#!/usr/bin/python
import pexpect
import time
import sys
IP_Address= '10.197.225.226'
Username = 'hey'
Password= 'hey'
session = pexpect.spawn("telnet " + IP_Address)
result= session.expect(["Username:"])
if result!=0:
print("-----Failure connection")
exit()
session.sendline(Username)
result= session.expect(["Password:"])
session.sendline(Password)
result= session.expect(["#"])
print('success')
C2=input('How many commands you want to enter:')
for i in range (0,C2):
C1=raw_input('Enter the commands:' )
session.expect('#')
session.sendline(C1)
session.logfile= open("Result1.txt","w")
print('Done')
请帮忙!
注意:我是新来的。
我正在使用 Python 2.7.6(默认,2016 年 10 月 26 日,20:30:19) [GCC 4.8.4] 在 linux2 上 输入“help”、“copyright”、“credits”或“license”了解更多信息。
【问题讨论】:
标签: python python-2.7