- Firstly in the code, i would like to know How can i add a for loop for CH (1-11) instead of writing for every number
- Also how to extract SUCCESS and FAILED message from the output (reference) For example i want the output as
CH1 : Failed
CH2: SUCCESS
CH3: Failed
: so on
I want to use regular expression and not json for this.
import pexpect
def quick_test():
ch = pexpect.spawn('ssh to server')
ch.logfile = sys.stdout
ch.expect("Select channels")
print ("\n########################################\n")
ch.sendline("1")
ch.expect("Enter ch to run:")
ch.sendline("CH1,0")
var1=ch.after
print(var1)
ch.expect("Enter Test:")
var2=ch.before
print(var2)
ch.sendline("CH2,0")
ch.expect("Enter Test:")
var3=ch.before
print(var3)
ch.sendline("CH3,0")
ch.expect("Enter Test:")
var4=ch.before
print(var4)
ch.sendline("CH4,0")
ch.expect("Enter Test:")
var5=ch.before
print(var5)
ch.sendline("CH5,0")
ch.expect("Enter Test:")
var6=ch.before
print(var6)
ch.sendline("CH6,0")
ch.expect("Enter Test:")
var7=ch.before
print(var7)
ch.sendline("CH7,0")
ch.expect("Enter Test:")
var8=ch.before
print(var8)
ch.sendline("CH8,0")
ch.expect("Enter Test:")
var9=ch.before
print(var9)
ch.sendline("CH9,0")
ch.expect("Enter Test:")
var10=ch.before
print(var10)
ch.sendline("CH10,0")
ch.expect("Enter Test:")
var11=ch.before
print(var11)
ch.sendline("CH11,0")
if __name__ == '__main__':
quick_test()
output:
output
###########################################
There are plenty of output displayed in which these below lines are included and
not in the given order and are displayed randomly.
CH1,0 Result: FAILED
CH2,0 Result: SUCCESS
CH3,0 Result: FAILED
CH4,0 Result: SUCCESS
CH5,0 Result: SUCCESS
CH6,0 Result: SUCCESS
CH7,0 Result: FAILED
CH8,0 Result: SUCCESS
CH9,0 Result: FAILED
CH10,0 Result: SUCCESS
CH11,0 Result: FAILED