开发者

how to switch from posix to windows with cygwin

开发者 https://www.devze.com 2023-04-12 13:17 出处:网络
im writing a python script that is being executed in cygwin.one of the things its doing is calling pg_dump and passing it a file name.my problem, python/cygwin is passing it a posix path and the windo

im writing a python script that is being executed in cygwin. one of the things its doing is calling pg_dump and passing it a file name. my problem, python/cygwin is passing it a posix path and the windows version of pg_dump doesn't know what to do with it. is there something that i can call to convert my posix path to a windows path?

i want to convert this path

/cygdrive/c/Users/me/Code开发者_如何学Go/myproj/pyBuildScript/src/snapshooter/working/sso.sql

to

c:\Users\me\Code\myproj\pyBuildScript\src\snapshooter\working\sso.sql


cygpath -w

You can read the manual page for more switches. Among them

  • -w for windows
  • -u for unix
  • -a for absolute path

You need to be careful with escaping, make sure the path argument is a single shell word.


You can do the following:

>>> posix_str = "/cygdrive/c/Users/me/Code/myproj/pyBuildScript/src/snapshooter/working/sso.sql"
>>> nt_str = "C:" + posix_str[11:]
>>> nt_str = nt_str.replace("/", "\\")
>>> print nt_str
C:\Users\me\Code\myproj\pyBuildScript\src\snapshooter\working\sso.sql
0

精彩评论

暂无评论...
验证码 换一张
取 消