diff --git a/pcl_expect/spawn.py b/pcl_expect/spawn.py index 6fb2701553943e0c75dcabd8311cf66a477d4c41..a1a431549291668c51aecc099bd539087d4e98a0 100644 --- a/pcl_expect/spawn.py +++ b/pcl_expect/spawn.py @@ -67,6 +67,7 @@ import os import sys import pty +import errno import fcntl import pcl_expect @@ -226,6 +227,20 @@ class Spawn(pcl_expect.Expectable): pcl_expect.debug("sending \"%s\" to fd %d" % (s, self.fileno())) os.write(self.fileno(), s) + def _read(self): + # When reading from a pty, at least under Linux, you get EIO + # when the process dies. Treat this as a normal end-of-file. + try: + return pcl_expect.Expectable._read(self) + except OSError, err: + if err.errno == errno.EIO: + return "", True + raise + + def kill(self, sig): + """Send signal SIG to the child process.""" + os.kill(self.__child_pid, sig) + def close(self): """Close the pty and wait for the child to die.