谁能告诉我,我们必须给出什么提示才能期望 python 脚本有一个空格。我需要执行一个命令,该命令只有在它看到期望提示后才会执行。手动执行时我得到了提示是一个空格,并且还必须通过脚本获得相同的提示。
导入 pexpect 导入 pxssh 导入时间 导入 os,re,sys
def ssh(ipaddr,password): 试试:
ss = pexpect.spawn(ipaddr)
print ipaddr
ss.logfile = open("/tmp/mynewlog", "a")
print "SSH connecting"
print
except:
print "connection refused"
print
#sys.exit()
try:
print password
ss.expect (':')
ss.sendline (password +"\n")
print "connected"
time.sleep(30)
ss.expect (">")
print "connection established"
print
except:
print "Permission denied, please try again."
print
sys.exit()
try:
ss.sendline ('taskkill /F /IM iperf.exe\n')
time.sleep(30)
ss.expect ('>')
ss.sendline ('cd /D D:\iperf-2.0.5-2-win32\n')
ss.expect ('>')
ss.sendline ('iperf -s\n')#########This command i need to execute and i'm expecting a blank space as prompt
ss.sendline (pexpect.EOF)
print "END"
ssh()
除了:打印“执行命令失败”
打印sys.exit()