diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index d6a6557..46e423f 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -2075,10 +2075,21 @@ class InteractiveShell(SingletonConfigurable, Magic): cmd : str Command to execute. """ + cmd = self.var_expand(cmd, depth=2) + # protect os.system from UNC paths on Windows, which it can't handle: + if sys.platform == 'win32': + from IPython.utils._process_win32 import AvoidUNCPath + with AvoidUNCPath() as path: + if path is not None: + cmd = '"pushd %s &&"%s' % (path, cmd) + ec = os.system(cmd) + else: + ec = os.system(cmd) + # We explicitly do NOT return the subprocess status code, because # a non-None value would trigger :func:`sys.displayhook` calls. # Instead, we store the exit_code in user_ns. - self.user_ns['_exit_code'] = os.system(self.var_expand(cmd, depth=2)) + self.user_ns['_exit_code'] = ec # use piped system by default, because it is better behaved system = system_piped diff --git a/IPython/frontend/terminal/interactiveshell.py b/IPython/frontend/terminal/interactiveshell.py index a57ecca..fbfe89c 100644 --- a/IPython/frontend/terminal/interactiveshell.py +++ b/IPython/frontend/terminal/interactiveshell.py @@ -112,11 +112,9 @@ class TerminalInteractiveShell(InteractiveShell): config=config, profile_dir=profile_dir, user_ns=user_ns, user_global_ns=user_global_ns, custom_exceptions=custom_exceptions ) - # use os.system instead of utils.process.system by default, except on Windows - if os.name == 'nt': - self.system = self.system_piped - else: - self.system = self.system_raw + # use os.system instead of utils.process.system by default, + # because piped system doesn't make sense in the Terminal: + self.system = self.system_raw self.init_term_title() self.init_usage(usage)