Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get native windows path inside msys python?

Tags:

python

msys2

When inside msys2-Python (3.4.3), how am I supposed to get the native windows path of some file from the msys-filesystem?

I want to write a configuration file for a native windows application so the msys path rewriting does not come into account.

There is a solution, but I don't like it, because I have to feed an unknown path into a shell:

path = "/home/user/workspace"
output = subprocess.check_output( 'cmd //c echo ' + path, shell = True )

This returns C:/msys64/home/user/workspace.

This question is not really a duplicate of Convert POSIX->WIN path, in Cygwin Python, w/o calling cygpath because it is about msys2.

like image 911
Uwe Koloska Avatar asked Jan 05 '17 18:01

Uwe Koloska


1 Answers

MSYS2 comes with a utility named cygpath that you can use. Run cygpath -w NAME. cygpath is a command-line utility in /usr/bin that you can run the same way you would run any other command-line utility. The output will be a Windows-style path corresponding to the NAME argument you passed.

like image 50
David Grayson Avatar answered Sep 29 '22 09:09

David Grayson