![](/img/trans.png)
[英]Python pexpect scripts run without error,but there are no outputs in output file
[英]Pexpect: Not able to redirect outputs to a file
问题:设备的输出未重定向到文件。 程序:根据我的程序,我已登录到一台设备并尝试收集少量输出。这里是程序。
#!/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')
请帮忙!
注意:我是新来的。
我在linux2上使用Python 2.7.6(默认值,2016年10月26日,20:30:19)[GCC 4.8.4]键入“ help”,“ copyright”,“ credits”或“ license”以获取更多信息。
我自己修好了。 在打开功能中使用a +。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.