Issue in pexpect when text wraps within session

Viewed 19

I am working on a pexpect script that is running populating an output file name and then a prompt for the file's parameters.

The program that the script runs asks for Device: then Parameters: always on the same line.... so if the file path-name that is entered for Device is long, sometimes the Parameters prompt wraps to the next line.

My code looks like.. child.expect_exact('Device:') child.sendline('/umcfiles/ftp_dir/ftp_peoplesoft/discount/AES_DISCOUNT_15010.TXT') child.expect_exact('Parameters:')

This times out.. and here is what is in child.before ' /umcfiles/ftp_dir/ftp_peoplesoft/discount/AES_DISCOUNT_15010.TXT Param\r\neters: "RWSN" => '

so the expect fails... (a child.expect('Parameters:') also fails)

How can I ignore the \r\n if it is there, because depending on the length of the path/filename I am using it may not be there at all, or be in a different position.

Thanks!

1 Answers

Actually... I found a way to calculate how much is left on the given line, and dynamically set my expect to how much of the Parameter prompt should be visible... seems to be working

#look for end of line and fix how much of 'Parameters:' we look for in pexpect
dlen = 80-len('Device: /umcfiles/ftp_dir/ftp_peoplesoft/discount/AES_DISCOUNT_15010.TXT')
pstr='Parameters:'
if dlen > len(pstr):
   dlen=len(pstr)
else:
   dlen=dlen-3 #remove the /r/n
child.expect(pstr[0:dlen])
Related