popen pipes fail when cwd is a UNC path

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tim Black

    #1

    popen pipes fail when cwd is a UNC path

    In my recent experience, popen os pipes always fail when cwd is a UNC
    path. Can anyone shed any light on this? Although I've seen lots of
    UNC path-related problems in this newsgroup, I've not been able to
    find anything specifically about os pipes and UNC paths.

    Here's a session dump that demonstrates what I'm talking about:

    Python 2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit (Intel)]
    on win32
    Type "help", "copyright" , "credits" or "license" for more information.[color=blue][color=green][color=darkred]
    >>> os.getcwd()[/color][/color][/color]
    'c:\\Python23'[color=blue][color=green][color=darkred]
    >>> f=os.popen("dir "); r=f.read(); print f.close()[/color][/color][/color]
    None[color=blue][color=green][color=darkred]
    >>> os.getcwd()[/color][/color][/color]
    'c:\\Python23'[color=blue][color=green][color=darkred]
    >>> os.chdir("c:\\" )
    >>> os.getcwd()[/color][/color][/color]
    'c:\\'[color=blue][color=green][color=darkred]
    >>> f=os.popen("dir "); r=f.read(); print f.close()[/color][/color][/color]
    None[color=blue][color=green][color=darkred]
    >>> os.chdir("\\\\T imb\\Python23")
    >>> os.getcwd()[/color][/color][/color]
    '\\\\Timb\\Pyth on23'[color=blue][color=green][color=darkred]
    >>> f=os.popen("dir "); r=f.read(); print f.close()[/color][/color][/color]
    1

    As you can see, this last pipe fails. This only happens when cwd is a
    UNC path. Please let me know if you have seen this, solved this, know
    a nice workaround, etc. as I find this quite annoying.

    Thanks,
    Tim
  • Mark Hadfield

    #2
    Re: popen pipes fail when cwd is a UNC path

    Tim Black wrote:[color=blue]
    > In my recent experience, popen os pipes always fail when cwd is a UNC
    > path. Can anyone shed any light on this? Although I've seen lots of
    > UNC path-related problems in this newsgroup, I've not been able to
    > find anything specifically about os pipes and UNC paths.[/color]

    It's a problem with the Windows command interpreter (cmd.exe on the NT
    family) which gets invoked by popen. To demonstrate this. try cd'ing to
    a UNC path. You will get a message like

    '\\foo\bar' is an invalid current directory path. UNC paths are not
    supported.


    --
    Mark Hadfield "Ka puwaha te tai nei, Hoea tatou"
    m.hadfield@niwa .co.nz
    National Institute for Water and Atmospheric Research (NIWA)

    Comment

    • Steve Christensen

      #3
      Re: popen pipes fail when cwd is a UNC path

      In article <cho314$4e1$1@n ewsreader.mailg ate.org>, Mark Hadfield wrote:[color=blue]
      > Tim Black wrote:[color=green]
      >> In my recent experience, popen os pipes always fail when cwd is a UNC
      >> path. Can anyone shed any light on this? Although I've seen lots of
      >> UNC path-related problems in this newsgroup, I've not been able to
      >> find anything specifically about os pipes and UNC paths.[/color]
      >
      > It's a problem with the Windows command interpreter (cmd.exe on the NT
      > family) which gets invoked by popen. To demonstrate this. try cd'ing to
      > a UNC path. You will get a message like
      >
      > '\\foo\bar' is an invalid current directory path. UNC paths are not
      > supported.[/color]

      It won't be directly applicable to the original problem... But, you can
      use 'pushd' on a UNC path. It will temporarily map the UNC path to a
      drive letter. When you do a 'popd' it will unmap the drive letter.

      -Steve

      Comment

      Working...