summaryrefslogtreecommitdiff
path: root/pexpect/__init__.py
diff options
context:
space:
mode:
authorjquast <contact@jeffquast.com>2014-08-24 15:06:15 -0700
committerjquast <contact@jeffquast.com>2014-08-24 15:06:15 -0700
commite2ff2f47fc7719ebf4375eec81f996362816bb10 (patch)
treeb8cdf2ee0ebf80d2a977c785eaefb085a5335cf2 /pexpect/__init__.py
parent8d96042177a6986ae5b117e31916638309b2fd03 (diff)
downloadpexpect-git-e2ff2f47fc7719ebf4375eec81f996362816bb10.tar.gz
Closes issue #86 and issue #100
Fallback to using stdout, and, when both stdin and stdout are *both* closed, catch ValueError and use the same constants as when the attached process is not a terminal.
Diffstat (limited to 'pexpect/__init__.py')
-rw-r--r--pexpect/__init__.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/pexpect/__init__.py b/pexpect/__init__.py
index 4a34f15..06dbac4 100644
--- a/pexpect/__init__.py
+++ b/pexpect/__init__.py
@@ -498,12 +498,17 @@ class spawn(object):
# inherit EOF and INTR definitions from controlling process.
try:
from termios import VEOF, VINTR
- fd = sys.__stdin__.fileno()
+ try:
+ fd = sys.__stdin__.fileno()
+ except ValueError:
+ # ValueError: I/O operation on closed file
+ fd = sys.__stdout__.fileno()
self._INTR = ord(termios.tcgetattr(fd)[6][VINTR])
self._EOF = ord(termios.tcgetattr(fd)[6][VEOF])
- except (ImportError, OSError, IOError, termios.error):
+ except (ImportError, OSError, IOError, ValueError, termios.error):
# unless the controlling process is also not a terminal,
- # such as cron(1). Fall-back to using CEOF and CINTR.
+ # such as cron(1), or when stdin and stdout are both closed.
+ # Fall-back to using CEOF and CINTR. There
try:
from termios import CEOF, CINTR
(self._INTR, self._EOF) = (CINTR, CEOF)