# Buggy code
def system(cmd):
    """Win32 version of os.system() that works with network shares.

    Note that this implementation returns None, as meant for use in IPython.

    Parameters
    ----------
    cmd : str
      A command to be executed in the system shell.

    Returns
    -------
    None : we explicitly do NOT return the subprocess status code, as this
    utility is meant to be used extensively in IPython, where any return value
    would trigger :func:`sys.displayhook` calls.
    """
    # The controller provides interactivity with both
    # stdin and stdout
    import _process_win32_controller

    _process_win32_controller.system(cmd)


# Traceback (TypeError)
TypeError                                 Traceback (most recent call last)
c:\Users\jmarch\<ipython-input-2-56af63bcfcf6> in <module>()
----> 1 get_ipython().magic(u'cd ..')

c:\users\jmarch\ipython\IPython\core\interactiveshell.pyc in magic(self, arg_s, next_input)
2034                 self._magic_locals = sys._getframe(1).f_locals
2035             with self.builtin_trap:
-> 2036                 result = fn(magic_args)
2037             # Ensure we're not keeping object references around:
2038             self._magic_locals = {}

c:\users\jmarch\ipython\IPython\core\magic.pyc in magic_cd(self, parameter_s)
2953             # for c:\windows\directory\names\
2954             parameter_s = re.sub(r'\\(?! )','/', parameter_s)
-> 2955             opts,ps = self.parse_options(parameter_s,'qb',mode='string')
2956         # jump to previous
2957         if ps == '-':

c:\users\jmarch\ipython\IPython\core\magic.pyc in parse_options(self, arg_str, opt_str, *long_opts, **kw)
279             # If the list of inputs only has 0 or 1 thing in it, there's no
280             # need to look for options
--> 281             argv = arg_split(arg_str, posix, strict)
282             # Do regular option processing
283             try:

c:\users\jmarch\ipython\IPython\utils\_process_win32.pyc in arg_split(commandline, posix, strict)
178         result_pointer = CommandLineToArgvW(py3compat.cast_unicode(commandline.lstrip()), ctypes.byref(argvn))
179         result_array_type = LPCWSTR * argvn.value
--> 180         result = [arg for arg in result_array_type.from_address(result_pointer)]
181         retval = LocalFree(result_pointer)
182         return result

TypeError: integer expected

# Fixed code
def system(cmd):
    """Win32 version of os.system() that works with network shares.

    Note that this implementation returns None, as meant for use in IPython.

    Parameters
    ----------
    cmd : str
      A command to be executed in the system shell.

    Returns
    -------
    None : we explicitly do NOT return the subprocess status code, as this
    utility is meant to be used extensively in IPython, where any return value
    would trigger :func:`sys.displayhook` calls.
    """
    # The controller provides interactivity with both
    # stdin and stdout
    # import _process_win32_controller
    # _process_win32_controller.system(cmd)

    with AvoidUNCPath() as path:
        if path is not None:
            cmd = '"pushd %s &&"%s' % (path, cmd)
        return process_handler(cmd, _system_body)