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
#4
Hi Tim/lucasbazan,
Thank you for your response.
I tried your suggestion but its not working for me.
I gone through the documentation and try adding few more arguments to the code, but still no luck. Pasted below is my code
from subprocess import Popen, PIPE

process=Popen(['/home/user/Automation/test_app', '-g'], stdout=PIPE, stderr=PIPE, stdin=PIPE, shell=True, universal_newlines=True)
print("return value",process)
stdout=process.communicate(input='y',timeout=3)
print(stdout)
while executing the code i am always getting timeout and pasted below is the error message /log.
Error:
user@user-laptop:~/Automation$ python3 sub.py return value <subprocess.Popen object at 0x7f8dd3046240> Traceback (most recent call last): File "sub.py", line 6, in <module> stdout=process.communicate(input='y',timeout=3) File "/usr/local/lib/python3.6/subprocess.py", line 843, in communicate stdout, stderr = self._communicate(input, endtime, timeout) File "/usr/local/lib/python3.6/subprocess.py", line 1515, in _communicate self._check_timeout(endtime, orig_timeout) File "/usr/local/lib/python3.6/subprocess.py", line 871, in _check_timeout raise TimeoutExpired(self.args, orig_timeout) subprocess.TimeoutExpired: Command '['/home/user/Automation/test_app', '-g']' timed out after 3 seconds user@user-laptop:~/Automation$
Note: After the error is occurring i am not able to run the script again in the same terminal, may be the process might me running in the background and occupying it.

Any other suggestions to solve this? Is there any way to know whether the executable got executed?
Or is there any way to see that message("Enable QSE API? (Y/n)" in the terminal itself?
Reply


Messages In This Thread
RE: Not able to read the text using pexpect/expect - by Bipinjohnson - Jan-07-2022, 06:05 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Reading and storing a line of output from pexpect child eagerissac 1 4,329 Feb-20-2024, 05:51 AM
Last Post: ayoshittu
  Read text file, modify it then write back Pavel_47 5 1,696 Feb-18-2023, 02:49 PM
Last Post: deanhystad
  read a text file, find all integers, append to list oldtrafford 12 3,747 Aug-11-2022, 08:23 AM
Last Post: Pedroski55
  Use pexpect to send user input alisha17 0 1,941 May-10-2022, 02:44 AM
Last Post: alisha17
  Sudden Problem with pexpect gw1500se 3 2,464 Nov-19-2021, 11:21 PM
Last Post: bowlofred
  How to use pexpect in python? tiho_bg 1 1,566 Oct-30-2021, 02:50 PM
Last Post: Yoriz
  [SOLVED] Read text file from some point till EOF? Winfried 1 2,003 Oct-10-2021, 10:29 PM
Last Post: Winfried
  Open and read multiple text files and match words kozaizsvemira 3 6,806 Jul-07-2021, 11:27 AM
Last Post: Larz60+
  Pexpect timesout before executing whole output eagerissac 0 1,539 Jun-23-2021, 03:30 AM
Last Post: eagerissac
  pexpect startup help korenron 2 3,531 Apr-27-2021, 07:23 AM
Last Post: korenron

Forum Jump:

User Panel Messages

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