##// END OF EJS Templates
IPython/utils/_process_posix.py: import pexpect only when needed
Matthias Koeppe -
Show More
@@ -20,8 +20,6 b' import os'
20 import subprocess as sp
20 import subprocess as sp
21 import sys
21 import sys
22
22
23 import pexpect
24
25 # Our own
23 # Our own
26 from ._process_common import getoutput, arg_split
24 from ._process_common import getoutput, arg_split
27 from IPython.utils.encoding import DEFAULT_ENCODING
25 from IPython.utils.encoding import DEFAULT_ENCODING
@@ -51,6 +49,7 b' class ProcessHandler(object):'
51 @property
49 @property
52 def sh(self):
50 def sh(self):
53 if self._sh is None:
51 if self._sh is None:
52 import pexpect
54 shell_name = os.environ.get("SHELL", "sh")
53 shell_name = os.environ.get("SHELL", "sh")
55 self._sh = pexpect.which(shell_name)
54 self._sh = pexpect.which(shell_name)
56 if self._sh is None:
55 if self._sh is None:
@@ -83,6 +82,7 b' class ProcessHandler(object):'
83 file descriptors (so the order of the information in this string is the
82 file descriptors (so the order of the information in this string is the
84 correct order as would be seen if running the command in a terminal).
83 correct order as would be seen if running the command in a terminal).
85 """
84 """
85 import pexpect
86 try:
86 try:
87 return pexpect.run(self.sh, args=['-c', cmd]).replace('\r\n', '\n')
87 return pexpect.run(self.sh, args=['-c', cmd]).replace('\r\n', '\n')
88 except KeyboardInterrupt:
88 except KeyboardInterrupt:
@@ -104,6 +104,7 b' class ProcessHandler(object):'
104 file descriptors (so the order of the information in this string is the
104 file descriptors (so the order of the information in this string is the
105 correct order as would be seen if running the command in a terminal).
105 correct order as would be seen if running the command in a terminal).
106 """
106 """
107 import pexpect
107 try:
108 try:
108 return pexpect.run(self.sh, args=['-c', cmd]).replace('\r\n', '\n')
109 return pexpect.run(self.sh, args=['-c', cmd]).replace('\r\n', '\n')
109 except KeyboardInterrupt:
110 except KeyboardInterrupt:
@@ -121,6 +122,8 b' class ProcessHandler(object):'
121 -------
122 -------
122 int : child's exitstatus
123 int : child's exitstatus
123 """
124 """
125 import pexpect
126
124 # Get likely encoding for the output.
127 # Get likely encoding for the output.
125 enc = DEFAULT_ENCODING
128 enc = DEFAULT_ENCODING
126
129
General Comments 0
You need to be logged in to leave comments. Login now