Python Forum
How to use pexpect in python?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to use pexpect in python?
#1
I would like to control a robot using pexpect. Here is my code:

#!/usr/bin/env python

from pexpect import pxssh
import pexpect

s = pxssh.pxssh()
s.login('ubiquityrobot.local', 'ubuntu', 'ubuntu')
print 'Start'
s.sendline('rosrun simple_nav control.py')
s.prompt()
print(s.before)
s.expect('Load Path Name?', timeout=5)
s.sendline('yes')
s.prompt()
print(s.before)
s.expect('Enter the name of the Path:', timeout=5)
s.sendline('4')
s.prompt()
print(s.before)
s.expect('Load Path Name? ')
s.sendline('no')
s.prompt()
print(s.before)
s.logout()
The script is working fine till the end. Finally the script is closing with an error related with the timeout and eof. How to resolve this error? Please, help!
Yoriz write Oct-30-2021, 02:44 PM:
Please post all code, output and errors (in their 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.
Reply
#2
Maybe the following can help
https://pexpect.readthedocs.io/en/stable...t-patterns Wrote:Special EOF and TIMEOUT patterns
There are two special patterns to match the End Of File (EOF) or a Timeout condition (TIMEOUT). You can pass these patterns to expect(). These patterns are not regular expressions. Use them like predefined constants.

If the child has died and you have read all the child’s output then ordinarily expect() will raise an EOF exception. You can read everything up to the EOF without generating an exception by using the EOF pattern expect. In this case everything the child has output will be available in the before property.
...
... (see the link for more)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Reading and storing a line of output from pexpect child eagerissac 1 4,144 Feb-20-2024, 05:51 AM
Last Post: ayoshittu
  Use pexpect to send user input alisha17 0 1,826 May-10-2022, 02:44 AM
Last Post: alisha17
  Not able to read the text using pexpect/expect Bipinjohnson 7 3,937 Jan-10-2022, 11:21 AM
Last Post: Bipinjohnson
  Sudden Problem with pexpect gw1500se 3 2,322 Nov-19-2021, 11:21 PM
Last Post: bowlofred
  Pexpect timesout before executing whole output eagerissac 0 1,450 Jun-23-2021, 03:30 AM
Last Post: eagerissac
  pexpect startup help korenron 2 3,429 Apr-27-2021, 07:23 AM
Last Post: korenron
  Problem with pexpect.exception.TimeOUT korenron 0 3,240 Apr-12-2021, 03:25 PM
Last Post: korenron
  Request help on pexpect rsurathu 4 5,721 Jul-19-2020, 03:35 PM
Last Post: snippsat
  SIGWINCH ignored when trying to start a screen with the pexpect module StatTark 0 1,791 Jul-06-2020, 10:12 AM
Last Post: StatTark
  Collecting Output from Pexpect gw1500se 3 3,813 Jul-20-2019, 08:42 PM
Last Post: gw1500se

Forum Jump:

User Panel Messages

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