Python Forum
Not able to read the text using pexpect/expect
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Not able to read the text using pexpect/expect
#3
Hi @Bipinjohnson ,
In the documentation of expect() you can read:
Quote:Strings will be compiled to re types
. This means your expected string is a dangerous one because it will be treated as a regular expression:
'Enable QSE API? (Y/n)'
The question mark means the previous character must appear 0 or 1 time. The parenthesis also have a meaning of capturing substrings. So you should escape those characters:
'Enable QSE API\? \(Y\/n\)'
I am not sure if this works. Play it safe and just check for:
'Enable QSE API'

Then also: you do not check if the string is found. You should check the returned value.
return_val=child.expect(['Enable QSE API'])
#if i receive the same string then i want to pass y to the terminal
if return_val == 0:
    child.sendline('y')
else:
    print("The expected string was not found")
    sys.exit()
Reply


Messages In This Thread
RE: Not able to read the text using pexpect/expect - by ibreeden - Jan-07-2022, 10:59 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question why I can't use "try" without "expect" xMaxrayx 4 325 May-17-2024, 12:25 PM
Last Post: DeaD_EyE
  Reading and storing a line of output from pexpect child eagerissac 1 4,434 Feb-20-2024, 05:51 AM
Last Post: ayoshittu
  Read text file, modify it then write back Pavel_47 5 1,799 Feb-18-2023, 02:49 PM
Last Post: deanhystad
  read a text file, find all integers, append to list oldtrafford 12 3,912 Aug-11-2022, 08:23 AM
Last Post: Pedroski55
  Use pexpect to send user input alisha17 0 2,030 May-10-2022, 02:44 AM
Last Post: alisha17
  Sudden Problem with pexpect gw1500se 3 2,504 Nov-19-2021, 11:21 PM
Last Post: bowlofred
  How to use pexpect in python? tiho_bg 1 1,603 Oct-30-2021, 02:50 PM
Last Post: Yoriz
  [SOLVED] Read text file from some point till EOF? Winfried 1 2,070 Oct-10-2021, 10:29 PM
Last Post: Winfried
  Open and read multiple text files and match words kozaizsvemira 3 6,871 Jul-07-2021, 11:27 AM
Last Post: Larz60+
  Pexpect timesout before executing whole output eagerissac 0 1,600 Jun-23-2021, 03:30 AM
Last Post: eagerissac

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020