tags:

views:

69

answers:

1

All machines are on Windows Server 2003.

If I only install cygwin on one of the machine and run my python script on it to manipulate files from all remote hosts. How can I access to those files via UNC path?

+2  A: 

Cygwin understands UNC pathnames that use two forward slashes (as opposed to the two backslashes typical of Windows -- in fact, under Cygwin, you must use forward slashes instead of backslashes anywhere in the path). I assume that this support would be propagated through to Python running on top of Cygwin, but I haven't ever tried it to confirm.

Edit: if you don't need to run python under cygwin, as you mention in a comment, then why are you doing so? Just install the native windows python from the python download site and forget about Cygwin. You'll probably have to double your backslashes in the path names, however, since IIRC Python uses backslash as an escape character, so to get one backslash in the final string you need to put in two.

rmeador
Confirmed it works, thanks.
Stan
@Stan: if it works, then please accept it :) You may also want to see my edit in response to your comment that you don't need cygwin.
rmeador
> You'll probably have to double your backslashes in the path names ...You can make it more readable using literal raw strings. E.g. `r'\\path\to\UNC'`.
Santa
Regarding to non-cygwin way, should I run the python script in windows command line? I tried type "myscript.py r'\\path\to\UNC'", but didn't work.
Stan
@Stan that should work... did the installer give you an option to register .py files as executable? I think you have to turn that on. Otherwise, you can probably achieve the same effect by putting the name of the python interpreter as the first thing on the command line.
rmeador
Actually it can work in the way without escape backslash, like "myscript.py \\path\to\UNC". So my question is in @rmeador's edit, what's the environment that needs to escape backslash? If it's Python command line, how can change folder or find what's current location? Thanks.
Stan