Can any one please tell me, what is the prompt we have to give for expecting a blank space for a python script.I need to execute a command which will execute only after it sees the expect prompt.On doing manually i got that the prompt is a blank space,and has to expect the same prompt via script also.
import pexpect import pxssh import time import os,re,sys
def ssh(ipaddr,password): try:
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()
except:
print "Failed to execute the command"
print
sys.exit()
Edit:
ss.expect
takes any string as a regular expression, and uses it to search the output from a program. In your case, if you want to match the line before all the dashes, you can do
ss.expect(r'TCP window size: .*yte \(default\)')
More broadly, I'm not sure what you're trying to accomplish with this, but it might be helpful to look at this page.
Old:
I'm not sure what you mean when you say that you expect a blank space as prompt.
1) Is it really a space? If so ss.expect(' ')
seems like it should work.
2) Is there an end of line? If so ss.expect('\n')
seems like it should work.
3) Does iperf
really give you a prompt? Is it really waiting for input? And you're sending an EOF? Does this kill the program?