![](/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.