0

I often need to know WSL mounted path names from Windows. I have now seen many sketch solutions to the problem so I thought I should share MY WAY.

Use cases for this might be running a linux tool against something running from cmd.exe or gdb debugging something from a windows development environment.

As in: "C:\Windows\System32"="/mnt/c/Windows/System32"

1
  • for /F "delims=" %G in ('bash -c "wslpath -a -u '%APPDATA%'"') do @echo %G (supply any valid Windows path instead of %APPDATA%).
    – JosefZ
    Mar 7, 2019 at 21:15

1 Answer 1

0

Here is a trick I figured out.. The following line will pull the CWD aka %CD% and put it in a variable called LNX_PATH

    for /f %p in ('bash.exe -c "pwd"') do set LNX_PATH=%p

Here is a simplified batch file example that will use vi to open a text file called 'test.txt' from your Windows Documents directory.

@echo off

:: This is the path to the file I want to launch using vi...
Set WIN_DOC_PATH=%UserProfile%\Documents

:: Switch to that path, get the CWD (linux style) and switch back
pushd "%WIN_DOC_PATH%"
    for /f %%n in ('bash.exe -c "pwd"') do set LNX_DOC_PATH=%%n
popd

:: Launch vi (via bash) using the correct path format
bash.exe -c "vi %LNX_DOC_PATH%/test.txt"

When this batch exits, you will be back at cmd.exe right where you started.

If someone has a better (non sketchy) way to get this path, I would love to know it!

1
  • Ahh.. there is a tool called wslpath that will do similar things. Mar 7, 2019 at 20:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .