Hi,
I am new to python i am trying some automation where in i want to call a terminal application from python and control the same.
I have tried Pexpect where i am able to open the application, but not able to read the contents from the terminal.
pasted below is my code:
Note: When i am tying to run the application manually, everything works fine.
Looking forward for some guidance from experts.
Regards
Johnson
I am new to python i am trying some automation where in i want to call a terminal application from python and control the same.
I have tried Pexpect where i am able to open the application, but not able to read the contents from the terminal.
pasted below is my code:
import pexpect child = pexpect.spawn ('./test_app -g',timeout=3,encoding='utf-8') #i am expecting the below string return_val=child.expect(['Enable QSE API? (Y/n)']) #if i receive the same string then i want to pass y to the terminal child.sendline('y') #now i am expecting the below string child.expect('Enable log? (Y/n)') child.sendline("y")When i execute the above script always timeout occurs and gets the below erorr/log message:Error:user@user-laptop:~/Automation$ python3 script_v1.py Traceback (most recent call last): File "script_v1.py", line 5, in <module> return_val=child.expect(['Enable QSE API? (Y/n)']) File "/usr/local/lib/python3.6/site-packages/pexpect/spawnbase.py", line 344, in expect timeout, searchwindowsize, async_) File "/usr/local/lib/python3.6/site-packages/pexpect/spawnbase.py", line 372, in expect_list return exp.expect_loop(timeout) File "/usr/local/lib/python3.6/site-packages/pexpect/expect.py", line 181, in expect_loop return self.timeout(e) File "/usr/local/lib/python3.6/site-packages/pexpect/expect.py", line 144, in timeout raise exc pexpect.exceptions.TIMEOUT: Timeout exceeded. <pexpect.pty_spawn.spawn object at 0x7fae358ece10> command: ./test_app args: [b'./test_app', b'-g'] buffer (last 100 chars): '\x1b[2J\x1b[1dEnable QSE API? (Y/n) ' before (last 100 chars): '\x1b[2J\x1b[1dEnable QSE API? (Y/n) ' after: <class 'pexpect.exceptions.TIMEOUT'> match: None match_index: None exitstatus: None flag_eof: False pid: 7737 child_fd: 5 closed: False timeout: 3 delimiter: <class 'pexpect.exceptions.EOF'> logfile: None logfile_read: None logfile_send: None maxread: 2000 ignorecase: False searchwindowsize: None delaybeforesend: 0.05 delayafterclose: 0.1 delayafterterminate: 0.1 searcher: searcher_re: 0: re.compile('Enable QSE API? (Y/n)') user@user-laptop:~/Automation$Something about the application: It runs on Ubuntu 18.x.x. terminal, once its started it will publish a menu and the user have to input the menu options.Note: When i am tying to run the application manually, everything works fine.
Looking forward for some guidance from experts.
Regards
Johnson
Larz60+ write Jan-06-2022, 11:04 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use bbcode tags on future posts.
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use bbcode tags on future posts.
