[Tutor] subprocess.Popen(..., cwd) and UNC paths

eryksun eryksun at gmail.com
Thu Apr 30 02:48:19 CEST 2015


On Wed, Apr 29, 2015 at 7:08 PM, Alan Gauld <alan.gauld at btinternet.com> wrote:
> On 30/04/15 00:12, eryksun wrote:
>
>> the working directory, but the cmd.exe shell (being a crusty relic of
>> the 1980s) does not.
>
> Actually cmd.exe is fine with UNC paths. It's only when you
> combine them with Windows /option style that it has issues
> but even then putting the path in quotes will usually do
> the trick.
>
> It's the old MS-DOS COMMAND.COM that can't cope.

cmd.exe was developed for OS/2 (1987) to replace COMMAND.COM (1981).

cmd.exe cannot use a UNC path as the current directory. What it can do
is `pushd` a UNC path, which mounts it as a drive letter. If you do
try to start cmd.exe with a UNC path as the working directory, it
instead sets the working directory to the Windows directory. For
example:

    (test) C:\Temp>python
    Python 3.4.2 (v3.4.2:ab2c023a9432, Oct  6 2014, 22:16:31)
    [MSC v.1600 64 bit (AMD64)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import os, subprocess
    >>> os.chdir(r'\\127.0.0.1\C$')
    >>> subprocess.call('cmd')
    '\\127.0.0.1\C$'
    CMD.EXE was started with the above path as the current directory.
    UNC paths are not supported.  Defaulting to Windows directory.
    Microsoft Windows [Version 6.1.7601]
    Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

    (test) C:\Windows>


More information about the Tutor mailing list