Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to open Windows file editing app from WSL

This answer states that the following will be possible:

For example, from the WSL command line you’ll be able to type code /mnt/c/Users/username/src/windows-file.txt to open a Windows file in
VS Code, or type code /home/username/src/linux-file.txt to open a
Linux file in VS Code.

is it already possible with the newest WSL 2 and Windows 11 21H2?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

At this point what I can do from inside WSL is to open the folder like this:

explorer.exe .

Which is already pretty awesome. But it would be even better to instead of running:

nano myfile.txt

open the file in Notepad++:

notepadpp myfile.txt

>Solution :

Sure, you can run any Windows executable this way.

notepad.exe myfile.txt will work, for example.

If your Notepad++ is in your PATH, then notepad++.exe would work too – mine isn’t, though, so I have to use the full path:

/mnt/c/Program\ Files/Notepad++/notepad++.exe myfile.txt

You can of course create a shell script or an alias to shorten this command.

Just note that if you specify a file with a path then you will have an issue because the Linux path is passed verbatim to the Windows executable, but that can be fixed with wslpath.

Here is an example shell script that you could put into ~/bin/notepadpp for example:

#!/bin/bash

/mnt/c/Program\ Files/Notepad++/notepad++.exe "$(wslpath -w "$1")"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading