##// END OF EJS Templates
store exit code in user_ns['_exit_code']...
MinRK -
Show More
@@ -1890,8 +1890,10 b' class InteractiveShell(SingletonConfigurable, Magic):'
1890 # if they really want a background process.
1890 # if they really want a background process.
1891 raise OSError("Background processes not supported.")
1891 raise OSError("Background processes not supported.")
1892
1892
1893 # don't return the result, always return None
1893 # we explicitly do NOT return the subprocess status code, because
1894 system(self.var_expand(cmd, depth=2))
1894 # a non-None value would trigger :func:`sys.displayhook` calls.
1895 # Instead, we store the exit_code in user_ns.
1896 self.user_ns['_exit_code'] = system(self.var_expand(cmd, depth=2))
1895
1897
1896 def system_raw(self, cmd):
1898 def system_raw(self, cmd):
1897 """Call the given cmd in a subprocess using os.system
1899 """Call the given cmd in a subprocess using os.system
@@ -1901,8 +1903,10 b' class InteractiveShell(SingletonConfigurable, Magic):'
1901 cmd : str
1903 cmd : str
1902 Command to execute.
1904 Command to execute.
1903 """
1905 """
1904 # don't return the result, always return None
1906 # We explicitly do NOT return the subprocess status code, because
1905 os.system(self.var_expand(cmd, depth=2))
1907 # a non-None value would trigger :func:`sys.displayhook` calls.
1908 # Instead, we store the exit_code in user_ns.
1909 self.user_ns['_exit_code'] = os.system(self.var_expand(cmd, depth=2))
1906
1910
1907 # use piped system by default, because it is better behaved
1911 # use piped system by default, because it is better behaved
1908 system = system_piped
1912 system = system_piped
@@ -130,9 +130,7 b' class ProcessHandler(object):'
130
130
131 Returns
131 Returns
132 -------
132 -------
133 None : we explicitly do NOT return the subprocess status code, as this
133 int : child's exitstatus
134 utility is meant to be used extensively in IPython, where any return
135 value would trigger :func:`sys.displayhook` calls.
136 """
134 """
137 pcmd = self._make_cmd(cmd)
135 pcmd = self._make_cmd(cmd)
138 # Patterns to match on the output, for pexpect. We read input and
136 # Patterns to match on the output, for pexpect. We read input and
@@ -181,6 +179,7 b' class ProcessHandler(object):'
181 finally:
179 finally:
182 # Ensure the subprocess really is terminated
180 # Ensure the subprocess really is terminated
183 child.terminate(force=True)
181 child.terminate(force=True)
182 return child.exitstatus
184
183
185 def _make_cmd(self, cmd):
184 def _make_cmd(self, cmd):
186 return '%s -c "%s"' % (self.sh, cmd)
185 return '%s -c "%s"' % (self.sh, cmd)
@@ -96,6 +96,9 b' def _system_body(p):'
96 line = line.decode(enc, 'replace')
96 line = line.decode(enc, 'replace')
97 print(line, file=sys.stderr)
97 print(line, file=sys.stderr)
98
98
99 # Wait to finish for returncode
100 return p.wait()
101
99
102
100 def system(cmd):
103 def system(cmd):
101 """Win32 version of os.system() that works with network shares.
104 """Win32 version of os.system() that works with network shares.
@@ -116,7 +119,7 b' def system(cmd):'
116 with AvoidUNCPath() as path:
119 with AvoidUNCPath() as path:
117 if path is not None:
120 if path is not None:
118 cmd = '"pushd %s &&"%s' % (path, cmd)
121 cmd = '"pushd %s &&"%s' % (path, cmd)
119 process_handler(cmd, _system_body)
122 return process_handler(cmd, _system_body)
120
123
121
124
122 def getoutput(cmd):
125 def getoutput(cmd):
General Comments 0
You need to be logged in to leave comments. Login now