任何人都可以告诉我,为了给python脚本预留一个空格,我们必须给出什么提示。我需要执行一个命令,只有在它看到期望提示。在做手动我得到的提示是一个空格,并且必须通过脚本也期望相同的提示。pexpect提示输入python中的空格
进口Pexpect的 进口pxssh 进口时间 进口操作系统,重,SYS
高清SSH(IPADDR,密码): 尝试:
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()
除了: 打印“无法执行命令“
print sys.exit()
欢迎使用stackoverflow。我认为你们的问题对我们大多数人来说有点模糊。看起来你正在使用'pexpect'包,但是大多数看这个问题的人可能从来没有使用它。如果你可以编辑你的问题给我们一个你已经尝试过的例子,并且更清楚地解释你期望发生的事情,它可能会有所帮助。 – Mike 2013-04-25 12:45:44
感谢迈克..我会更新我的问题 – abhi 2013-04-25 13:01:49
@abhi我现在也将更新您的问题与答案定义什么麦克的答案下面提供。您将在未来帮助其他人,并以这种方式得到答案。 – TryTryAgain 2013-04-25 16:52:23